Created
January 17, 2018 11:33
-
-
Save RonenNess/e6a46848f08e3dd0ea25f9d187088187 to your computer and use it in GitHub Desktop.
Django basic log config - creates file and console handlers and add all installed apps by default to the main log file.
This file contains 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
# Dump this at the end of your setting file. | |
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': False, | |
'formatters': { | |
'verbose': { | |
'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s", | |
'datefmt': "%d/%b/%Y %H:%M:%S" | |
}, | |
'simple': { | |
'format': '%(levelname)s %(message)s' | |
}, | |
}, | |
'handlers': { | |
'file': { | |
'level': 'INFO', | |
'filename': 'log.log', | |
'class': 'logging.handlers.RotatingFileHandler', | |
'maxBytes': 1024*1024*5, | |
'backupCount': 10, | |
'formatter': 'verbose' | |
}, | |
'console': { | |
'level': 'INFO', | |
'class': 'logging.StreamHandler', | |
}, | |
}, | |
'loggers': { | |
'django': { | |
'handlers': ['file', 'console'], | |
'level': 'WARNING', | |
'propagate': True, | |
}, | |
}, | |
} | |
# create loggers for all apps | |
for installed_app_name in INSTALLED_APPS: | |
LOGGING['loggers'][installed_app_name] = { | |
'handlers': ['file', 'console'], | |
'level': 'DEBUG', | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment