python(2.5.2)的日志记录机制是什么?有没有Log4j看起来像Python/Geodjango的库或标准类?



我计划在我的pythongeodjango web服务中添加日志机制。是否有log4j看起来像python/geodjango的日志机制?

我正在寻找log4j的dailyrollingfileappender等效。然后自动删除所有1个月前的日志文件。

任何指导都是感激的。

UPDATES1 我在考虑下面的格式。

datetime(ms)|log level|current thread name|client ip address|logged username|source file|source file line number|log message

是- Python 2.5包含'logging'模块。它支持的处理程序之一是handlers.TimedRotatingFileHandler,这就是你要找的。'logging'很容易使用:

的例子:

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

下面是你的日志配置文件

#======================
# mylog.conf
[loggers]
keys=root
[handlers]
keys=default
[formatters]
keys=default
[logger_root]
level=INFO
handlers=default
qualname=(root) # note - this is used in non-root loggers
propagate=1 # note - this is used in non-root loggers
channel=
parent=
[handler_default]
class=handlers.TimedRotatingFileHandler
level=INFO
formatter=default
args=('try.log', 'd', 1)
[formatter_default]
format=%(asctime)s %(pathname)s(%(lineno)d): %(levelname)s %(message)s

最新更新