如何使用Django 1.3日志字典配置设置SysLogHandler [英] How to setup SysLogHandler with Django 1.3 logging dictionary configuration

查看:553
本文介绍了如何使用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':'% level $)$ {


'处理程序':{
'syslog':{
'level':'DEBUG' ,
'class':'logging.handlers.SysLogHandler',
'formatter':'verbose'
},

},
' ':{
'django':{
'handlers':['syslog'],
'propagate':True,
'level':'INFO',
},
'myapp':{
'处理程序':['syslog'],
'宣传':True,
'level':'DEBUG',
},
},
}


解决方案

最后找到答案,将原始问题的配置修改为对于'syslog'有以下内容:

  from logging.handlers import SysLogHandler 
...
' syslog':{
'level':'DEBUG',
'class':'logging.handlers.SysLogHandler',
'formatter':'verbose',
' ':SysLogHandler.LOG_LOCAL2,
},
...

向后代发出警告:您几乎完全按照上述方式执行,如果直接指定课程等,则会出现奇怪的错误。



更新:我刚刚搬到了Amazon Linux(和Django 1.5),并使用了以下更改配置该环境中的syslog部分,请注意地址参数:

 'syslog':{
'level':'DEBUG',
'class':'logging.handlers.SysLogHandler',
'formatter':'verbose',
'facility':'local1',
'address':'/ dev / log',
},


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',
        },
    },
}

解决方案

Finally found the answer, modify the configuration in the original question to have the following for 'syslog':

from logging.handlers import SysLogHandler 
... 
        'syslog':{ 
            'level':'DEBUG', 
            'class': 'logging.handlers.SysLogHandler', 
            'formatter': 'verbose', 
            'facility': SysLogHandler.LOG_LOCAL2, 
        },
...

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:

    'syslog':{
        'level':'DEBUG',
        'class': 'logging.handlers.SysLogHandler',
        'formatter': 'verbose',
        'facility': 'local1',
        'address': '/dev/log',
    },

这篇关于如何使用Django 1.3日志字典配置设置SysLogHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆