💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
```python # 文件日志handler名 COMMON_HANDLER = "common_handler" # 通用日志 FILE_HANDLER = "file_handler" # 文件日志 # 通用格式 formatter = logging.Formatter( fmt="%(asctime)s %(levelname)s %(filename)s %(funcName)s %(lineno)d %(message)s", datefmt="%Y-%m-%d %H:%M:%S") # 日志处理器配置 handler_config_dict = { COMMON_HANDLER: { 'filename': 'common.log', # 文件名 'when': 'D', # 翻转间隔类型 'interval': 7, # 翻转间隔 'backupCount': 4 # 备份数 }, FILE_HANDLER: { 'filename': 'file.log', # 文件名 'when': 'D', # 翻转间隔类型 'interval': 7, # 翻转间隔 'backupCount': 4 # 备份数 } } logger_common = logging.getLogger(COMMON_HANDLER) logger_file = logging.getLogger(FILE_HANDLER) logger_common.setLevel(logging.DEBUG) logger_file.setLevel(logging.DEBUG) handler_config_common = handler_config_dict[COMMON_HANDLER] handler_config_file = handler_config_dict[FILE_HANDLER] handler_common = logging.handlers.TimedRotatingFileHandler(filename=settings.BASE_DIR + "/logs/" + handler_config_common['filename'], when=handler_config_common['when'], interval=handler_config_common['interval'], backupCount=handler_config_common['backupCount']) handler_common.setFormatter(formatter) handler_common.suffix = "%Y-%m-%d_%H-%M-%S.log" logger_common.addHandler(handler_common) handler_file = logging.handlers.TimedRotatingFileHandler(filename=settings.BASE_DIR + "/logs/" + handler_config_file['filename'], when=handler_config_file['when'], interval=handler_config_file['interval'], backupCount=handler_config_file['backupCount']) handler_file.setFormatter(formatter) handler_file.suffix = "%Y-%m-%d_%H-%M-%S.log" logger_file.addHandler(handler_file) ```