How to setup SysLogHandler with Django 1.3 logging dictionary configuration

后端 未结 2 1988
灰色年华
灰色年华 2021-02-07 06:09

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 docum

2条回答
  •  走了就别回头了
    2021-02-07 06:46

    This works for me (on default debian).

    1. I suspect using an address of /dev/log is the secret to ensure there is no attempt to use the network.
    2. I think using a logger label of '' equates to the root logger so will catch most stuff

    In settings.py:

    LOGGING = {
        'version': 1,
        'handlers': {
            'syslog':{
                'address': '/dev/log',
                'class': 'logging.handlers.SysLogHandler'
            }
        },
        'loggers': {
            '': {
                'handlers': ['syslog'],
                'level': 'DEBUG',
            }
        }
    }
    

    in the app:

        import logging
        logging.info("freakout info")
    

    provides:

    john:/var/log$ sudo tail -1 user.log
    Dec 14 17:15:52 john freakout info
    

提交回复
热议问题