使用dictConfig配置Python日志

时间:2018-08-23 16:02:46

标签: python python-3.x logging

我正在尝试在3.4.8中配置如下内容:

### Create the logger
logger = logging.getLogger('basic_logger')
logger.setLevel(logging.DEBUG)

### Setup the console handler with a StringIO object
log_capture_string = io.StringIO()
ch = logging.StreamHandler(log_capture_string)
ch.setLevel(logging.DEBUG)

在我的配置文件中。

在我的特定情况下,我试图配置ioHandler以将消息“写入”到StringIO变量中。

  "handlers" : { 
    "fileHandler": {"filters": ["log_filter"], "class": "logging.FileHandler", "level": "INFO","formatter": "fileFormatter","filename": "tester.log"},
    "streamHandler": { "filters": ["log_filter"], "class": "logging.StreamHandler", "formatter": "streamFormatter","level": "DEBUG","stream": "ext://sys.stdout"},
    "ioHandler": { "filters": ["io_filter"], "class": "logging.StreamHandler", "formatter": "streamFormatter","level": "DEBUG","stream": "??WHAT DO I PUT HERE??"}
  },

0 个答案:

没有答案