2012-01-04

Python logging 标准配置

Views: 16396 | 1 Comment
# encoding=UTF-8
import logging
import logging.config

logging.addLevelName(5, 'TRACE')
logging.addLevelName(30, 'WARN')
logging.addLevelName(50, 'FATAL')

logging.config.fileConfig('my.conf')
logger = logging.getLogger('root')

my.conf:

[loggers]
keys=root

[handlers]
keys=consoleHandler, fileHandler

[formatters]
keys=simpleFormatter

[logger_root]
#level=ERROR
level=DEBUG
handlers=consoleHandler, fileHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=simpleFormatter
args=('a.log', 'a')

[formatter_simpleFormatter]
#format=%(asctime)s [%(levelname)-5s] %(name)s %(message)s
format=%(asctime)s [%(levelname)-5s] %(message)s
#datefmt= %Y-%m-%d %H:%M:%S
datefmt= 

Related posts:

  1. C#封装log4net
  2. .Net程序中使用log4net记录日志
  3. Docker镜像常用操作
  4. 如何使用ServletContextListener
  5. Windows Python select标准输入输出
Posted by ideawu at 2012-01-04 17:10:57

One Response to "Python logging 标准配置"

Leave a Comment