【问题标题】:TimedRotatingFileHandler not working with dictconfigTimedRotatingFileHandler 不适用于 dictconfig
【发布时间】:2018-12-05 09:12:40
【问题描述】:

这就是我从配置文件中读取配置的方式

config.dictConfig(final_config_file)

这是我的 configuration.json 文件。

{
  "logging": {
    "version": 1,
    "root": {
      "handlers": [
        "file_handler"
      ],
      "level": "DEBUG"
    },
    "disable_existing_loggers": false,
    "handlers": {
      "file_handler": {
        "class": "logging.handlers.TimedRotatingFileHandler",
        "formatter": "json",
        "when": "midnight",
        "backupCount": 0,
        "filename": "C:/Users/desaijb/Desktop/gitpractice/log.json"
      }
    },

我正在使用 timedrotatinghandler 在日期更改时旋转文件,但不知何故它不起作用,我无法按时间更改文件。我已将它设置在午夜,但它无法正常工作。任何帮助都会得到帮助。

【问题讨论】:

    标签: python logging multiprocessing


    【解决方案1】:

    将“backupCount”设置为非零。要理解它,请阅读the docs

    如果backupCount 不为零,则最多保留backupCount 个文件,如果发生翻转时会创建更多文件,则删除最旧的文件。删除逻辑使用间隔来确定要删除哪些文件,因此更改间隔可能会留下旧文件。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多