什么是python(2.5.2)的日志记录机制?有没有log4j看起来像库或标准类的python/geodjango会做什么?

ero*_*ros 5 python logging geodjango

我打算在我的python和geodjango Web服务中添加日志记录机制.log4j在python/geodjango中看起来像一个类似的日志记录机制吗?

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

任何指导表示赞赏.

更新1 我正在考虑以下格式.

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

小智 3

是的 - Python 2.5 包含“日志记录”模块。它支持的处理程序之一是handlers.TimedRotatingFileHandler,这就是您正在寻找的。“logging”非常容易使用:

例子:

import logging
import logging.config

logging.fileConfig('mylog.conf')
logger = logging.getLogger('root')
Run Code Online (Sandbox Code Playgroud)

以下是您的日志记录配置文件

#======================

# 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
Run Code Online (Sandbox Code Playgroud)