Skip to content

Instantly share code, notes, and snippets.

@willywongi
Created March 8, 2021 16:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save willywongi/fe416aea5df43bf3d138c0e09f66fdad to your computer and use it in GitHub Desktop.
Save willywongi/fe416aea5df43bf3d138c0e09f66fdad to your computer and use it in GitHub Desktop.
Python logging configuration example
import logging
import logging.config
logging.dictConfig({
'version': 1,
'disable_existing_loggers': False,
"formatters": {
"standard": {
"format": '%(asctime)s %(name)s %(levelname)s %(message)s'
}
},
'handlers': {
'file': {
'level': 'DEBUG',
'filename': 'activity.log',
'formatter': 'standard',
"class": "logging.handlers.RotatingFileHandler",
"maxBytes": 1048576, # 1MB
"backupCount": 0 # keep all the files
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'INFO',
'propagate': True
},
'backend': {
'handlers': ['file'],
'level': 'DEBUG',
}
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment