Last active
January 24, 2022 08:52
-
-
Save woile/5e66981d03d4da863dd9 to your computer and use it in GitHub Desktop.
Custom logging for django with colors in console
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
logger = logging.getLogger(__name__) | |
logger.debug("bla bla") | |
logger.info("bla bla") | |
logger.warning("bla bla") | |
logger.error("bla bla") | |
logger.critical("bla bla") |
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
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': False, | |
'handlers': { | |
'mail_admins': { | |
'level': 'ERROR', | |
'class': 'django.utils.log.AdminEmailHandler' | |
}, | |
'console': { | |
'level': 'DEBUG', | |
'class': 'logging.StreamHandler', | |
'formatter': 'colorful' | |
}, | |
'file': { | |
'level': 'INFO', | |
'class': 'logging.FileHandler', | |
'filename': 'django_info.log', | |
'formatter': 'verbose' | |
}, | |
}, | |
'formatters': { | |
'verbose': { | |
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' | |
}, | |
'simple': { | |
'format': '%(levelname)s %(message)s' | |
}, | |
'colorful': { | |
'format': '\033[1;34m%(levelname)s \033[1;35m%(name)s:%(module)s \033[0m%(funcName)s %(message)s' | |
}, | |
}, | |
'loggers': { | |
'django.request': { | |
'handlers': ['mail_admins'], | |
'level': 'INFO', | |
'propagate': True, | |
}, | |
'app_name': { | |
'handlers': ['console', 'file'], | |
'level': 'INFO', | |
#'filters': ['special'] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment