簡體   English   中英

配置日志記錄在python中使用logging.config.dictConfig時出錯

[英]Error when config logging use logging.config.dictConfig in python

首先,我正在使用python。嘗試通過config json文件配置日志記錄並使用logging.config.dictConfig() 。我之前使用過它並且效果很好。 但是這次我刪除了一點,並且有些刪除是行不通的。 我的配置文件將如下所示:

{
    "version": 1,
    "disable_existing_loggers": false,
    "formatters": {
        "simple": {
            "format": "%(name)-6s | %(levelname)-8s | %(message)s"
        },
        "info_format": {
            "format": "%(name)-6s | %(levelname)-6s | %(message)s"
        },
        "error_format": {
            "format": "%(filename)-8s | %(module)-12s | %(funcName)s | %(lineno)d : %(message)s"
        },
        "debug_format": {
             "format": "%(filename)-8s | %(module)-12s | %(funcName)s | %(lineno)d : %(message)s"
        }
    },
    "handlers": {
        "console": {
             "class": "logging.StreamHandler",
             "level": "DEBUG",
             "formatter": "simple",
             "stream": "ext://sys.stdout"
        },
        "info_handler": {
            "level": "INFO",
            "formatter": "info_format",
            "encoding": "utf8",
            "stream": "ext://sys.stdout"
        },
        "error_handler": {
            "level": "ERROR",
            "formatter": "error_format",
            "encoding": "utf8",
            "stream": "ext://sys.stderr"
        }
    },
    "loggers": {
        "info": {
             "level": "INFO",
             "handlers": ["console"],
             "propagate": "no"
         },
         "error": {
             "level": "ERROR",
             "handlers": ["console"],
             "propagate": "no"
         },
         "tornado.access": {
             "level": "INFO",
             "handlers": ["console"],
             "propagate": "no"
         },
         "tornado.general": {
             "level": "INFO",
             "handlers": ["console"],
             "propagate": "no"
         },
         "tornado.application": {
             "level": "ERROR",
             "handlers": ["console"],
             "propagate": "no"
         }
    }

}

這是我配置日志記錄的方式:

configParser = ConfigParser.ConfigParser()
__ProjectPath = os.getcwd()
config_path = __ProjectPath + "/configs/logconfig.json"
with open(config_path, 'rt') as f:
    configs = json.loads(f.read())
    logging.config.dictConfig(configs)

那是錯誤信息:

Traceback (most recent call last):
  File "/home/jonah/code/leancloud-demo/wsgi.py", line 13, in <module>
    from app import app
  File "/home/jonah/code/leancloud-demo/app.py", line 14, in <module>
    import log
  File "/home/jonah/code/leancloud-demo/log.py", line 51, in <module>
    logging.config.dictConfig(configs)
  File "/usr/lib/python2.7/logging/config.py", line 794, in dictConfig
    dictConfigClass(config).configure()
  File "/usr/lib/python2.7/logging/config.py", line 576, in configure
    '%r: %s' % (name, e))
ValueError: Unable to configure handler u'error_handler': 'NoneType' object has no attribute 'split'

Process finished with exit code 1

我有一段時間的谷歌,只是無法回答。對不起我的英語不好。

閱讀https://docs.python.org/2/library/logging.config.html#dictionary-schema-details

// class (mandatory). This is the fully qualified name of the handler class

"info_handler": {
    "class": "logging.StreamHandler",
    "level": "INFO",
    "formatter": "info_format",
    "stream": "ext://sys.stdout"
},
"error_handler": {
    "class": "logging.StreamHandler",
    "level": "ERROR",
    "formatter": "error_format",
    "stream": "ext://sys.stderr"
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM