def __init__(self, *args, **kwargs): logging.LogRecord.__init__(self, *args, **kwargs) reset = TextFormat('reset') # pylint: disable=E1321 self.colorname = '%s[%-17s]%s' % (LOG_COLORS['name'], self.name, reset) self.colorlevel = '%s[%-8s]%s' % (LOG_COLORS['levels'][self.levelname], self.levelname, TextFormat('reset')) self.colorprocess = '%s[%5s]%s' % (LOG_COLORS['process'], self.process, reset) self.colormsg = '%s%s%s' % (LOG_COLORS['msgs'][self.levelname], self.msg, reset)
def __init__(self, *args, **kwargs): SaltLogRecord.__init__(self, *args, **kwargs) reset = TextFormat('reset') clevel = LOG_COLORS['levels'].get(self.levelname, reset) cmsg = LOG_COLORS['msgs'].get(self.levelname, reset) # pylint: disable=E1321 self.colorname = '%s[%-17s]%s' % (LOG_COLORS['name'], self.name, reset) self.colorlevel = '%s[%-8s]%s' % (clevel, self.levelname, TextFormat('reset')) self.colorprocess = '%s[%5s]%s' % (LOG_COLORS['process'], self.process, reset) self.colormsg = '%s%s%s' % (cmsg, self.getMessage(), reset)
def __init__(self, *args, **kwargs): logging.LogRecord.__init__(self, *args, **kwargs) self.colorname = '{tf}[{name:17}]{end}'.format(tf=LOG_COLORS['name'], name=self.name, end=TextFormat('reset')) self.colorlevel = '{tf}[{levelname:8}]{end}'.format( tf=LOG_COLORS['levels'][self.levelname], levelname=self.levelname, end=TextFormat('reset')) self.colorprocess = '{tf}[{process}]{end}'.format( tf=LOG_COLORS['process'], process=self.process, end=TextFormat('reset')) self.colormsg = u'{tf}{msg}{end}'.format( tf=LOG_COLORS['msgs'][self.levelname], msg=self.msg, end=TextFormat('reset'))
LOG_LEVELS = { 'all': logging.NOTSET, 'debug': logging.DEBUG, 'error': logging.ERROR, 'critical': logging.CRITICAL, 'garbage': GARBAGE, 'info': logging.INFO, 'profile': PROFILE, 'quiet': QUIET, 'trace': TRACE, 'warning': logging.WARNING, } LOG_COLORS = { 'levels': { 'QUIET': TextFormat('reset'), 'CRITICAL': TextFormat('bold', 'red'), 'ERROR': TextFormat('bold', 'red'), 'WARNING': TextFormat('bold', 'yellow'), 'INFO': TextFormat('bold', 'green'), 'PROFILE': TextFormat('bold', 'cyan'), 'DEBUG': TextFormat('bold', 'cyan'), 'TRACE': TextFormat('bold', 'magenta'), 'GARBAGE': TextFormat('bold', 'blue'), 'NOTSET': TextFormat('reset'), }, 'msgs': { 'QUIET': TextFormat('reset'), 'CRITICAL': TextFormat('bold', 'red'), 'ERROR': TextFormat('red'), 'WARNING': TextFormat('yellow'),
'debug': logging.DEBUG, 'error': logging.ERROR, 'critical': logging.CRITICAL, 'garbage': GARBAGE, 'info': logging.INFO, 'profile': PROFILE, 'quiet': QUIET, 'trace': TRACE, 'warning': logging.WARNING, } LOG_VALUES_TO_LEVELS = dict((v, k) for (k, v) in LOG_LEVELS.items()) LOG_COLORS = { 'levels': { 'QUIET': TextFormat('reset'), 'CRITICAL': TextFormat('bold', 'red'), 'ERROR': TextFormat('bold', 'red'), 'WARNING': TextFormat('bold', 'yellow'), 'INFO': TextFormat('bold', 'green'), 'PROFILE': TextFormat('bold', 'cyan'), 'DEBUG': TextFormat('bold', 'cyan'), 'TRACE': TextFormat('bold', 'magenta'), 'GARBAGE': TextFormat('bold', 'blue'), 'NOTSET': TextFormat('reset'), 'SUBDEBUG': TextFormat('bold', 'cyan'), # used by multiprocessing.log_to_stderr() 'SUBWARNING': TextFormat('bold', 'yellow'), # used by multiprocessing.log_to_stderr() },
def get_colors(use=True, theme=None): ''' Return the colors as an easy to use dict. Pass `False` to deactivate all colors by setting them to empty strings. Pass a string containing only the name of a single color to be used in place of all colors. Examples: .. code-block:: python colors = get_colors() # enable all colors no_colors = get_colors(False) # disable all colors red_colors = get_colors('RED') # set all colors to red ''' colors = { 'BLACK': TextFormat('black'), 'DARK_GRAY': TextFormat('bold', 'black'), 'RED': TextFormat('red'), 'LIGHT_RED': TextFormat('bold', 'red'), 'GREEN': TextFormat('green'), 'LIGHT_GREEN': TextFormat('bold', 'green'), 'YELLOW': TextFormat('yellow'), 'LIGHT_YELLOW': TextFormat('bold', 'yellow'), 'BLUE': TextFormat('blue'), 'LIGHT_BLUE': TextFormat('bold', 'blue'), 'MAGENTA': TextFormat('magenta'), 'LIGHT_MAGENTA': TextFormat('bold', 'magenta'), 'CYAN': TextFormat('cyan'), 'LIGHT_CYAN': TextFormat('bold', 'cyan'), 'LIGHT_GRAY': TextFormat('white'), 'WHITE': TextFormat('bold', 'white'), 'DEFAULT_COLOR': TextFormat('default'), 'ENDC': TextFormat('reset'), } if theme: colors.update(get_color_theme(theme)) if not use: for color in colors: colors[color] = '' if isinstance(use, six.string_types): # Try to set all of the colors to the passed color if use in colors: for color in colors: # except for color reset if color == 'ENDC': continue colors[color] = colors[use] return colors