Skip to content

Instantly share code, notes, and snippets.

@vsajip
Created February 11, 2013 17:23
Show Gist options
  • Save vsajip/4755918 to your computer and use it in GitHub Desktop.
Save vsajip/4755918 to your computer and use it in GitHub Desktop.
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()
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