Skip to content

Instantly share code, notes, and snippets.

@dalmosantos
Forked from willywongi/logging_config.py
Created April 30, 2022 00:06
Show Gist options
  • Save dalmosantos/2a43e252122cbb4f9a7b5c093d5587e1 to your computer and use it in GitHub Desktop.
Save dalmosantos/2a43e252122cbb4f9a7b5c093d5587e1 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