Created
February 11, 2013 17:23
-
-
Save vsajip/4755918 to your computer and use it in GitHub Desktop.
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 sys | |
from logutils.dictconfig import dictConfig | |
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': True, | |
'formatters': { | |
'standard': { | |
'format': "[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s", | |
'datefmt': "%d/%b/%Y %H:%M:%S" | |
}, | |
}, | |
'handlers': { | |
'console': { | |
'level': 'DEBUG', | |
'()': 'ext://custom_colorize.custom_colorizer', | |
'formatter': 'standard', | |
'level_map': { | |
logging.INFO: (None, 'cyan', True), | |
} | |
}, | |
}, | |
'loggers': { | |
'django': { | |
'handlers': ['console'], | |
'propagate': True, | |
'level': 'INFO', | |
} | |
} | |
} | |
def main(): | |
logging.getLogger('django').info('This should appear in BRIGHT CYAN in a terminal') | |
if __name__ == '__main__': | |
dictConfig(LOGGING) | |
main() |
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 sys | |
from logutils.colorize import ColorizingStreamHandler | |
def custom_colorizer(level_map): | |
result = ColorizingStreamHandler(sys.stdout) | |
lm = dict(result.level_map) # makes a copy of the dict in the class | |
lm.update(level_map) | |
result.level_map = lm # set dict into instance - class dict unchanged | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment