1
This commit is contained in:
@@ -21,48 +21,6 @@ from app.services.log_config import decrypt_data
|
|||||||
logging.basicConfig(level=logging.INFO if settings.DEBUG else logging.WARNING)
|
logging.basicConfig(level=logging.INFO if settings.DEBUG else logging.WARNING)
|
||||||
|
|
||||||
|
|
||||||
def _setup_payment_logger():
|
|
||||||
"""Configure a dedicated file logger for payment events.
|
|
||||||
|
|
||||||
Logs are written to logs/payment_YYYY-MM-DD.log, rotated daily.
|
|
||||||
30 days of history are retained.
|
|
||||||
"""
|
|
||||||
from logging.handlers import TimedRotatingFileHandler
|
|
||||||
log_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "logs")
|
|
||||||
os.makedirs(log_dir, exist_ok=True)
|
|
||||||
log_file = os.path.join(log_dir, "payment.log")
|
|
||||||
|
|
||||||
payment_logger = logging.getLogger("payment")
|
|
||||||
payment_logger.setLevel(logging.INFO)
|
|
||||||
payment_logger.propagate = False # don't double-log to root
|
|
||||||
|
|
||||||
# Avoid adding duplicate handlers on reload
|
|
||||||
if any(getattr(h, "_payment_file", False) for h in payment_logger.handlers):
|
|
||||||
return
|
|
||||||
|
|
||||||
handler = TimedRotatingFileHandler(
|
|
||||||
log_file,
|
|
||||||
when="midnight",
|
|
||||||
interval=1,
|
|
||||||
backupCount=30,
|
|
||||||
encoding="utf-8",
|
|
||||||
utc=False, # use local time
|
|
||||||
)
|
|
||||||
handler.suffix = "%Y-%m-%d" # files named like payment.log.2026-06-10
|
|
||||||
handler._payment_file = True # type: ignore[attr-defined]
|
|
||||||
handler.setFormatter(logging.Formatter(
|
|
||||||
"%(asctime)s [%(levelname)s] %(message)s",
|
|
||||||
datefmt="%Y-%m-%d %H:%M:%S",
|
|
||||||
))
|
|
||||||
payment_logger.addHandler(handler)
|
|
||||||
# Mirror to console in DEBUG mode
|
|
||||||
if settings.DEBUG:
|
|
||||||
payment_logger.addHandler(logging.StreamHandler())
|
|
||||||
|
|
||||||
|
|
||||||
_setup_payment_logger()
|
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
from app.models import async_session
|
from app.models import async_session
|
||||||
|
|||||||
@@ -158,6 +158,8 @@ def _get_alipay_client(app_id: str, private_key: str, public_key: str, gateway:
|
|||||||
config.sign_type = "RSA2"
|
config.sign_type = "RSA2"
|
||||||
config.charset = "utf-8"
|
config.charset = "utf-8"
|
||||||
config.cert_path = certifi.where()
|
config.cert_path = certifi.where()
|
||||||
|
os.environ["SSL_CERT_FILE"] = certifi.where()
|
||||||
|
os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()
|
||||||
try:
|
try:
|
||||||
_alipay_client = DefaultAlipayClient(config)
|
_alipay_client = DefaultAlipayClient(config)
|
||||||
_alipay_client_app_id = app_id
|
_alipay_client_app_id = app_id
|
||||||
|
|||||||
Reference in New Issue
Block a user