| Home | Trees | Indices | Help |
|---|
|
|
1 #!/usr/bin/env python3 2 # -*- coding: utf-8 -*- 3 4 """A class to format the log messages + the logger instance.""" 5 6 import os 7 import logging 8 9 10 CNRM = '\x1B[0m' 11 CBLK = '\x1B[30m' 12 CRED = '\x1B[31m' 13 CGRN = '\x1B[32m' 14 CYEL = '\x1B[33m' 15 CBLU = '\x1B[34m' 16 CMAG = '\x1B[35m' 17 CCYN = '\x1B[36m' 18 CWHT = '\x1B[37m' 19 BNRM = '\x1B[1m\x1b[00m' 20 BBLK = '\x1B[1m\x1b[30m' 21 BRED = '\x1B[1m\x1b[31m' 22 BGRN = '\x1B[1m\x1b[32m' 23 BYEL = '\x1B[1m\x1b[33m' 24 BBLU = '\x1B[1m\x1b[34m' 25 BMAG = '\x1B[1m\x1b[35m' 26 BCYN = '\x1B[1m\x1b[36m' 27 BWHT = '\x1B[1m\x1b[37m' 28 BOLD = '\x1B[1m' 29 3032 """Add color to log messages by overring logging.Formater methods.""" 33 34 FORMAT = ("[$BOLD%(filename)-8s: " 35 "%(funcName)20s():%(lineno)4s$RESET][%(levelname)-18s] " 36 "%(message)s ") 37 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8) 38 39 COLOR_SEQ = "\x1B[%dm" 40 41 COLORS = { 42 'WARNING': YELLOW, 43 'INFO': WHITE, 44 'DEBUG': BLUE, 45 'CRITICAL': YELLOW, 46 'ERROR': RED 47 } 4870 71 72 CF = ColorFormatter() 73 handler = logging.StreamHandler() 74 handler.setFormatter(CF) 75 #: The logger which can be used anywhere in the program 76 lg = logging.getLogger('root') 77 lg.setLevel(logging.DEBUG) 78 lg.addHandler(handler) 7950 msg = self.formatter_msg(self.FORMAT, use_color) 51 logging.Formatter.__init__(self, msg) 52 self.use_color = use_color5355 if use_color: 56 msg = msg.replace("$RESET", CNRM) 57 msg = msg.replace("$BOLD", BOLD) 58 else: 59 msg = msg.replace("$RESET", "") 60 msg = msg.replace("$BOLD", "") 61 return msg62
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Tue Jun 16 23:30:31 2015 | http://epydoc.sourceforge.net |