如何使用 Django 1.3 日志字典配置设置 SysLogHandler
我没有找到任何有关使用 Django 1.3 字典配置设置 syslog 日志记录的信息。 Django 文档不涵盖 syslog,而 python 文档不太清晰,根本不涵盖字典配置。我已从以下内容开始,但我一直不知道如何配置 SysLogHandler。
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'syslog':{
'level':'DEBUG',
'class':'logging.handlers.SysLogHandler',
'formatter': 'verbose'
},
},
'loggers': {
'django': {
'handlers':['syslog'],
'propagate': True,
'level':'INFO',
},
'myapp': {
'handlers': ['syslog'],
'propagate': True,
'level': 'DEBUG',
},
},
}
I'm having no luck finding any information on setting up syslog logging with Django 1.3 dictionary configuration. The Django documents don't cover syslog and the python documentation is less than clear and doesn’t cover dictionary config at all. I've started with the following but I'm stuck on how to configure the SysLogHandler.
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'syslog':{
'level':'DEBUG',
'class':'logging.handlers.SysLogHandler',
'formatter': 'verbose'
},
},
'loggers': {
'django': {
'handlers':['syslog'],
'propagate': True,
'level':'INFO',
},
'myapp': {
'handlers': ['syslog'],
'propagate': True,
'level': 'DEBUG',
},
},
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
终于找到了答案,修改原始问题中的配置,使“syslog”具有以下内容:
警告后代:你几乎必须完全按照上面的方式去做,如果你直接指定类等。
更新:我刚刚迁移到 Amazon Linux(和 Django 1.5),并对该环境中“syslog”部分的配置进行了以下更改,请注意“address”参数:
Finally found the answer, modify the configuration in the original question to have the following for 'syslog':
Warning to future generations: you pretty much have to do it exactly like the above, weird errors happen if you specify the class directly etc.
Update: I've just moved to Amazon Linux (and Django 1.5) and used the following change to the configuration for the 'syslog' section in that environment, note the 'address' argument:
这对我有用(在默认的 debian 上)。
/dev/log
地址是确保不会尝试使用网络的秘密。''
记录器标签相当于根记录器,因此可以捕获大多数内容In settings.py:
in the app:
提供:
This works for me (on default debian).
/dev/log
is the secret to ensure there is no attempt to use the network.''
equates to the root logger so will catch most stuffIn settings.py:
in the app:
provides:
如果您使用远程系统日志,请务必在地址字段中包含端口,否则您可能会收到
[Errno 9] Bad file detector
日志记录配置将如下所示
}
If you're using remote syslog, be sure to include the port in the address field, otherwise you could get
[Errno 9] Bad file descriptor
The logging config would look something like this
}