我已经编写了下面的日志记录配置文件。
[loggers]
keys=root, appName
[handlers]
keys=simpleFormatter, filelogformatter
[logger_root]
level=DEBUG
handlers=consoleHandler
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
arts=(sys.stdout,)
[logger_appName]
level=DEBUG
handlers=appNameHandler
qualname=appName
propagate=1
channel=appName
parent=(root)
[handler_appNameHandler]
class=handlers.TimedRotatingFileHandler
interval=midnight
backupCount=5
level=DEBUG
formatter=filelogformatter
args=('/specific/path/on/disk/project.log',)
[formatter_simpleFormatter]
format=%(asctime) s - %(levelname)s - %(name)s %(message)s
[formatter_filelogformatter]
format=%(asctime) s - %(levelname)s - %(name)s %(message)s
仅登录到控制台标准输出有效,但文件无效。
def get_logger(name=None):
"""
"""
logging_file=os.path.join(os.path.split(__file__) [0], 'logging.conf')
logging.config.fileConfig(logging_file)
_logger = logging.getLogger(name)
_logger.setLevel(logging.DEBUG)
return _logger