Created
March 8, 2021 16:57
-
-
Save willywongi/fe416aea5df43bf3d138c0e09f66fdad to your computer and use it in GitHub Desktop.
Python logging configuration example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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