记录多个模块

时间:2014-06-10 20:03:49

标签: python logging bottle

如何使用Python记录所有内容'记录'多个模块上的1个文本文件?

Main.py

import logging
logging.basicConfig(format='localhost - - [%(asctime)s] %(message)s', level=logging.DEBUG)
log_handler = logging.handlers.RotatingFileHandler('debug.out', maxBytes=2048576)


log = logging.getLogger('logger')
log.addHandler(log_handler)

import test

Test.py

import logging

log = logging.getLogger('logger')
log.error('test')

debug.out保持为空。即使在阅读了日志记录文档之后,我也不确定下一步该尝试什么。

修改:已修复上述代码。

1 个答案:

答案 0 :(得分:1)

设置正确的日志记录级别(如果要获取级别为ERROR或更高级别的所有消息,则至少为ERROR)并添加处理程序以将所有消息写入文件。有关详细信息,请查看https://docs.python.org/2/howto/logging-cookbook.html

相关问题