source: http://www.simonkrueger.com/2015/05/27/logging-django-apps-to-syslog.html
Django conf:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s - [%(asctime)s] - %(name)s.%(funcName)s:%(lineno)s - %(message)s'
}
},
'handlers': {
'apps': {
'level': 'DEBUG',
'class': 'logging.handlers.SysLogHandler',
'formatter': 'verbose',
'facility': 'local7',
'address': '/dev/log',
}
},
'loggers': {
'apps': {
'handlers': ['apps'],
'level': 'DEBUG',
'propagate': True,
}
}
}
/etc/rsyslog.d/30-mydjangoproject.conf
# /etc/rsyslog.d/30-mydjangoproject.conf
local7.* /var/log/mydjangoproject/apps.log
& ~ # This stops local7.* from going anywhere else.
/etc/logrotate.d/mydjangoproject
/var/log/mydjangoproject/apps.log {
daily
missingok
rotate 1000
compress
delaycompress
notifempty
dateext
dateyesterday
dateformat .%Y-%m-%d
extension .log
}
Create /var/log/mydjangoproject
and /var/log/mydjangoproject/apps.log
with appropriate permissions and restart rsyslog.