Skip to content

Instantly share code, notes, and snippets.

@artschwagerb
Last active July 22, 2020 13:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artschwagerb/df2372ccde3a062e7b1ed74eccccb696 to your computer and use it in GitHub Desktop.
Save artschwagerb/df2372ccde3a062e7b1ed74eccccb696 to your computer and use it in GitHub Desktop.
Django Logging to Syslog
from logging.handlers import SysLogHandler
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format' : "[YOUR PROJECT NAME] [%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
'verbose': {
'format': '%(process)-5d %(thread)d %(name)-50s %(levelname)-8s %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
'mail_admins': {
'level': 'INFO',
'class': 'django.utils.log.AdminEmailHandler'
},
'syslog': {
'class': 'logging.handlers.SysLogHandler',
'formatter': 'standard',
'facility': 'user',
# uncomment next line if rsyslog works with unix socket only (UDP reception disabled)
#'address': '/dev/log'
},
'file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': 'django.log',
},
},
'loggers': {
'django':{
'handlers': ['syslog'],
'level': 'INFO',
#'level': 'INFO',
'disabled': False,
'propagate': True
},
'django.request': {
'handlers': ['mail_admins'],
'level': 'WARNING',
'propagate': False,
}
}
}
# loggers for my apps, uses INSTALLED_APPS in settings
MY_LOGGERS = {}
for app in INSTALLED_APPS:
MY_LOGGERS[app] = {
'handlers': ['syslog'],
'level': 'DEBUG',
'propagate': True,
}
LOGGING['loggers'].update(MY_LOGGERS)
@nautics889
Copy link

What the reason of import statement at 1 line? It is not being using anywhere.

@artschwagerb
Copy link
Author

If you can comment it out and nothing bad happens. I assume it is a snippet of a 4 year old copy of the logging section of a project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment