Python colorlog.ColoredFormatter() Examples
The following are 30
code examples of colorlog.ColoredFormatter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
colorlog
, or try the search function
.
Example #1
Source File: misc.py From ibllib with MIT License | 7 votes |
def logger_config(name=None): import logging import colorlog """ Setup the logging environment """ if not name: log = logging.getLogger() # root logger else: log = logging.getLogger(name) log.setLevel(logging.INFO) format_str = '%(asctime)s.%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s' date_format = '%Y-%m-%d %H:%M:%S' cformat = '%(log_color)s' + format_str colors = {'DEBUG': 'green', 'INFO': 'cyan', 'WARNING': 'bold_yellow', 'ERROR': 'bold_red', 'CRITICAL': 'bold_purple'} formatter = colorlog.ColoredFormatter(cformat, date_format, log_colors=colors) stream_handler = logging.StreamHandler() stream_handler.setFormatter(formatter) log.addHandler(stream_handler) return log
Example #2
Source File: DatabasePort.py From Timeline with GNU General Public License v3.0 | 7 votes |
def InitiateColorLogger(name='twisted'): from colorlog import ColoredFormatter logger = logging.getLogger(name) stream = logging.StreamHandler() LogFormat = " %(reset)s%(log_color)s%(levelname)-8s%(reset)s | %(log_color)s%(message)s" stream.setFormatter(ColoredFormatter(LogFormat, log_colors={ 'DEBUG': 'white', 'INFO': 'cyan', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'black,bg_red', })) logger.addHandler(stream) logger.setLevel(logging.DEBUG) logger.info("Porter running") return logger
Example #3
Source File: AutoBrowser.py From AutoBrowser with GNU General Public License v3.0 | 6 votes |
def configure_logger(): """ This function is responsible to configure logging object. """ global LOGGER LOGGER = logging.getLogger("Autobrowser") # Set logging level LOGGER.setLevel(logging.DEBUG) # Create console handler log_colors = { 'DEBUG': 'bold_blue', 'INFO': 'green', 'WARNING': 'purple', 'ERROR': 'red', 'CRITICAL': 'bold_yellow', } formatter = "%(log_color)s[%(asctime)s] - %(message)s%(reset)s" formatter = ColoredFormatter(formatter, datefmt='%d-%m-%Y %H:%M', log_colors=log_colors) ch = logging.StreamHandler(sys.stdout) ch.setFormatter(formatter) LOGGER.addHandler(ch)
Example #4
Source File: sawadm.py From sawtooth-core with Apache License 2.0 | 6 votes |
def create_console_handler(verbose_level): clog = logging.StreamHandler() formatter = ColoredFormatter( "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s " "%(white)s%(message)s", datefmt="%H:%M:%S", reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red', }) clog.setFormatter(formatter) if verbose_level == 0: clog.setLevel(logging.WARN) elif verbose_level == 1: clog.setLevel(logging.INFO) else: clog.setLevel(logging.DEBUG) return clog
Example #5
Source File: sawnet.py From sawtooth-core with Apache License 2.0 | 6 votes |
def create_console_handler(verbose_level): clog = logging.StreamHandler() formatter = ColoredFormatter( "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s " "%(white)s%(message)s", datefmt="%H:%M:%S", reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red', }) clog.setFormatter(formatter) if verbose_level == 0: clog.setLevel(logging.WARN) elif verbose_level == 1: clog.setLevel(logging.INFO) else: clog.setLevel(logging.DEBUG) return clog
Example #6
Source File: sawset.py From sawtooth-core with Apache License 2.0 | 6 votes |
def create_console_handler(verbose_level): clog = logging.StreamHandler() formatter = ColoredFormatter( "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s " "%(white)s%(message)s", datefmt="%H:%M:%S", reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red', }) clog.setFormatter(formatter) if verbose_level == 0: clog.setLevel(logging.WARN) elif verbose_level == 1: clog.setLevel(logging.INFO) else: clog.setLevel(logging.DEBUG) return clog
Example #7
Source File: main.py From sawtooth-core with Apache License 2.0 | 6 votes |
def create_console_handler(verbose_level): clog = logging.StreamHandler() formatter = ColoredFormatter( "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s " "%(white)s%(message)s", datefmt="%H:%M:%S", reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red', }) clog.setFormatter(formatter) if verbose_level == 0: clog.setLevel(logging.WARN) elif verbose_level == 1: clog.setLevel(logging.INFO) else: clog.setLevel(logging.DEBUG) return clog
Example #8
Source File: katzkatz.py From KatzKatz with GNU General Public License v3.0 | 6 votes |
def configure_logger(): """ This function is responsible to configure logging object. """ global LOGGER LOGGER = logging.getLogger("KatzKatz") # Set logging level LOGGER.setLevel(logging.INFO) # Create console handler log_colors = { 'DEBUG': 'bold_red', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red', } formatter = "%(log_color)s[%(asctime)s] - %(message)s%(reset)s" formatter = ColoredFormatter(formatter, datefmt='%d-%m-%Y %H:%M', log_colors=log_colors) ch = logging.StreamHandler(sys.stdout) ch.setFormatter(formatter) LOGGER.addHandler(ch)
Example #9
Source File: dehr_cli.py From sawtooth-healthcare with Apache License 2.0 | 6 votes |
def create_console_handler(verbose_level): clog = logging.StreamHandler() formatter = ColoredFormatter( "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s " "%(white)s%(message)s", datefmt="%H:%M:%S", reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red', }) clog.setFormatter(formatter) if verbose_level == 0: clog.setLevel(logging.WARN) elif verbose_level == 1: clog.setLevel(logging.INFO) else: clog.setLevel(logging.DEBUG) return clog
Example #10
Source File: logger.py From Zeebsploit with Apache License 2.0 | 6 votes |
def logger(name): format_ = ColoredFormatter( '%(log_color)s%(levelname)s%(reset)s %(message)s', log_colors={ '[+]':'blue', '[!]':'yellow', '[-]':'red', '[x]':'red_bold', '[*]':'green' } ) logging.addLevelName(10,'[+]') logging.addLevelName(20,'[!]') logging.addLevelName(30,'[-]') logging.addLevelName(40,'[x]') logging.addLevelName(50,'[*]') logger = logging.getLogger(name) handler = logging.StreamHandler() handler.setFormatter(format_) logger.setLevel(logging.DEBUG) logger.addHandler(handler) return logger
Example #11
Source File: custom_logger.py From archon with MIT License | 6 votes |
def setup_logger(logger_name, log_file, level=logging.DEBUG): l = logging.getLogger(logger_name) formatter = logging.Formatter('[%(name)s] %(asctime)s : %(message)s') logdir = "./log/" if not os.path.exists(logdir): os.makedirs(logdir) fileHandler = logging.FileHandler(logdir + log_file, mode='w') fileHandler.setFormatter(formatter) l.setLevel(level) l.addHandler(fileHandler) handler = colorlog.StreamHandler() colorformat = colorlog.ColoredFormatter('%(log_color)s[%(name)s] %(message)s - (%(asctime)s) %(lineno)d') handler.setFormatter(colorformat) l.addHandler(handler)
Example #12
Source File: simplewallet_cli.py From sawtooth-simplewallet with Apache License 2.0 | 6 votes |
def create_console_handler(verbose_level): clog = logging.StreamHandler() formatter = ColoredFormatter( "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s " "%(white)s%(message)s", datefmt="%H:%M:%S", reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red', }) clog.setFormatter(formatter) clog.setLevel(logging.DEBUG) return clog
Example #13
Source File: log.py From OpenNIR with MIT License | 6 votes |
def logger(self): code = colorlog.escape_codes['thin_white'] console_formatter = colorlog.ColoredFormatter( f'{code}[%(asctime)s][%(name)s][%(levelname)s] %(reset)s%(log_color)s%(message)s') file_formatter = logging.Formatter('[%(asctime)s][%(name)s][%(levelname)s] %(message)s') handler = TqdmHandler() handler.setFormatter(console_formatter) if self.name not in _logger_cache: logger = logging.getLogger(self.name) logger.addHandler(handler) file_handler = logging.FileHandler(util.path_log()) file_handler.setFormatter(file_formatter) logger.addHandler(file_handler) logger.propagate = False logger.setLevel(logging.DEBUG) _logger_cache[self.name] = logger return _logger_cache[self.name]
Example #14
Source File: logger.py From hermes-audio-server with MIT License | 6 votes |
def get_logger(command, verbose, daemon): """Return a Logger object with the right level, formatter and handler.""" if daemon: handler = SysLogHandler(address=get_domain_socket()) formatter = logging.Formatter(fmt=DAEMON_FORMAT.format(command)) logger = logging.getLogger(command) else: handler = colorlog.StreamHandler(stream=sys.stdout) formatter = colorlog.ColoredFormatter(INTERACTIVE_FORMAT, log_colors=LOG_COLORS) logger = colorlog.getLogger(command) if verbose: logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.INFO) handler.setFormatter(formatter) logger.addHandler(handler) return logger
Example #15
Source File: __init__.py From python-zenlog with GNU General Public License v3.0 | 6 votes |
def __init__(self, lvl=logging.DEBUG, format=None): self._lvl = lvl if not format: format = " %(log_color)s%(styledname)-8s%(reset)s | %(log_color)s%(message)s%(reset)s" self.format = format logging.root.setLevel(self._lvl) self.formatter = colorlog.ColoredFormatter(self.format) self.stream = logging.StreamHandler() self.stream.setLevel(self._lvl) self.stream.setFormatter(self.formatter) self.logger = logging.getLogger('pythonConfig') self.logger.setLevel(self._lvl) self.logger.addHandler(self.stream) self.theme = THEME self.extra = {"styledname": self.theme[self._lvl]} # the magic happens here: we use the "extra" argument documented in # https://docs.python.org/2/library/logging.html#logging.Logger.debug # to inject new items into the logging.LogRecord objects # we also create our convenience methods here
Example #16
Source File: test.py From pybtc with GNU General Public License v3.0 | 6 votes |
def init(loop, argv): parser = argparse.ArgumentParser(description="Test node connector ...") args = parser.parse_args() config_file = "test.conf" log_level = logging.INFO logger = colorlog.getLogger('cn') config = configparser.ConfigParser() config.read(config_file) ch = logging.StreamHandler() ch.setLevel(log_level) formatter = colorlog.ColoredFormatter('%(log_color)s%(asctime)s %(levelname)s: %(message)s (%(module)s:%(lineno)d)') ch.setFormatter(formatter) logger.addHandler(ch) logger.setLevel(log_level) logger.info("Start") loop = asyncio.get_event_loop() app = App(loop, logger, config) return app
Example #17
Source File: psqworker.py From psq with Apache License 2.0 | 6 votes |
def setup_logging(): # pragma: no cover root_logger = logging.getLogger() root_logger.setLevel(logging.INFO) handler = logging.StreamHandler() formatter = ColoredFormatter( "%(log_color)s%(levelname)-8s%(reset)s %(asctime)s %(green)s%(name)s" "%(reset)s %(message)s", reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'blue', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red,bg_white', } ) handler.setFormatter(formatter) root_logger.addHandler(handler)
Example #18
Source File: config.py From cutelog with MIT License | 6 votes |
def init_logging(): log = logging.getLogger('CL') term_handler = logging.StreamHandler() try: import colorlog fmt = colorlog.ColoredFormatter('%(asctime)s %(log_color)s[%(name)12s:%(lineno)3s' ' %(funcName)18s ]\t%(levelname)-.6s %(message)s') except ImportError: fmt = logging.Formatter('%(asctime)s [%(name)12s:%(lineno)3s ' '%(funcName)18s ]\t%(levelname)-.6s %(message)s') term_handler.setFormatter(fmt) log.addHandler(term_handler) log.setLevel(logging.DEBUG) return log
Example #19
Source File: util.py From clusterman with Apache License 2.0 | 6 votes |
def setup_logging(log_level_str: str = 'info') -> None: EVENT_LOG_LEVEL = 25 logging.addLevelName(EVENT_LOG_LEVEL, 'EVENT') def event(self, message, *args, **kwargs): if self.isEnabledFor(EVENT_LOG_LEVEL): self._log(EVENT_LOG_LEVEL, message, args, **kwargs) # we're adding a new function to Logger so ignore the type here to make mypy happy logging.Logger.event = event # type: ignore handler = colorlog.StreamHandler() handler.setFormatter(colorlog.ColoredFormatter('%(log_color)s%(levelname)s:%(name)s:%(message)s')) logger = colorlog.getLogger() logger.addHandler(handler) log_level = getattr(logging, log_level_str.upper()) logging.getLogger().setLevel(log_level) logging.getLogger('botocore').setLevel(max(logging.INFO, log_level)) logging.getLogger('boto3').setLevel(max(logging.INFO, log_level))
Example #20
Source File: logging_interface.py From actinia_core with GNU General Public License v3.0 | 6 votes |
def getLogFormat(self, type): if type == 'stdout': format = global_config.LOG_STDOUT_FORMAT elif type == 'file': format = global_config.LOG_FILE_FORMAT if format == "json": return CustomJsonFormatter( '%(time) %(level) %(component) %(module)%(message) %(pathname)' ' %(lineno)%(processName) %(threadName)%(node)') else: return ColoredFormatter( '%(log_color)s[%(asctime)s] %(levelname)-10s: ' '%(name)s.%(module)-10s -%(message)s ' '[in %(pathname)s:%(lineno)d]%(reset)s' )
Example #21
Source File: log.py From uchroma with GNU Lesser General Public License v3.0 | 6 votes |
def get(cls, tag): """ Get the global logger instance for the given tag :param tag: the log tag :return: the logger instance """ if tag not in cls._LOGGERS: if cls._use_color: handler = colorlog.StreamHandler() handler.setFormatter(colorlog.ColoredFormatter( \ ' %(log_color)s%(name)s/%(levelname)-8s%(reset)s |' ' %(log_color)s%(message)s%(reset)s')) else: handler = logging.StreamHandler() handler.setFormatter(logging.Formatter( \ ' %(name)s/%(levelname)-8s | %(message)s')) logger = logging.getLogger(tag) logger.addHandler(handler) cls._LOGGERS[tag] = logger return cls._LOGGERS[tag]
Example #22
Source File: fridaPyBinding.py From Frida-Python-Binding with GNU General Public License v3.0 | 6 votes |
def setup_logging(): logger = logging.getLogger() logger.setLevel(logging.INFO) color_formatter = ColoredFormatter( "%(log_color)s[%(asctime)s] [%(levelname)-4s]%(reset)s - %(message)s", datefmt='%d-%m-%y %H:%M:%S', reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'bold_yellow', 'ERROR': 'bold_red', 'CRITICAL': 'bold_red', }, secondary_log_colors={}, style='%') logging_handler = logging.StreamHandler() logging_handler.setFormatter(color_formatter) logger.addHandler(logging_handler) # setup logging for script
Example #23
Source File: cookiejar.py From sawtooth-cookiejar with Apache License 2.0 | 6 votes |
def create_console_handler(verbose_level): '''Setup console logging.''' del verbose_level # unused clog = logging.StreamHandler() formatter = ColoredFormatter( "%(log_color)s[%(asctime)s %(levelname)-8s%(module)s]%(reset)s " "%(white)s%(message)s", datefmt="%H:%M:%S", reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red', }) clog.setFormatter(formatter) clog.setLevel(logging.DEBUG) return clog
Example #24
Source File: cmdline.py From statik with MIT License | 6 votes |
def configure_logging(verbose=False, quiet=False, fail_silently=False, colorize=True): handler = colorlog.StreamHandler() if colorize else logging.StreamHandler() formatter = colorlog.ColoredFormatter( '%(log_color)s%(asctime)s\t%(name)s\t%(levelname)s\t%(message)s' ) if colorize else logging.Formatter( '%(asctime)s\t%(name)s\t%(levelname)s\t%(message)s' ) handler.setFormatter(formatter) root_logger = logging.getLogger("") root_logger.addHandler(handler) root_logger.setLevel( logging.CRITICAL if quiet and fail_silently else logging.ERROR if quiet else logging.DEBUG if verbose else logging.INFO )
Example #25
Source File: logging.py From autogbt-alt with MIT License | 6 votes |
def _configure(): root = logging.getLogger() if root.handlers: return logger = logging.getLogger('autogbt') if logger.handlers: return handler = logging.StreamHandler() formatter = colorlog.ColoredFormatter( '%(log_color)s' '[%(levelname)s %(asctime)s %(name)s L%(lineno)d] ' '%(reset)s' '%(message)s', ) handler.setFormatter(formatter) logger.addHandler(handler) logger.setLevel(logging.INFO)
Example #26
Source File: logger.py From artman with Apache License 2.0 | 6 votes |
def setup_logger(name, level, colors=COLORS, format_string="%(purple)s%(name)s> %(log_color)s%(message)s"): """Set up a particular logger with overridden behavior. Args: name (str): The name of the logger. level (int): The log level to set this logger to. colors (dict): A dictionary of log colors. format_string (str): The format of the log message. """ logger_ = logging.getLogger(name) logger_.setLevel(level) formatter = ColoredFormatter(format_string, reset=True, log_colors=colors) if logger_.handlers: logger_.handlers.pop() handler = logging.StreamHandler() handler.setFormatter(formatter) logger_.addHandler(handler) logger_.propagate = False return logger_ # Make the logger and output_logger available for import from elsewhere.
Example #27
Source File: loggers.py From i3-xfce with GNU Lesser General Public License v3.0 | 6 votes |
def init_loggers(): """ Function initialize loggers """ formatter = ColoredFormatter("%(log_color)s%(levelname)-8s%(reset)s %(white)s%(message)s", datefmt=None, reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'white', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red,bg_white', }, secondary_log_colors={}, style='%' ) handler = logging.StreamHandler() handler.setFormatter(formatter) ROOTLOGGER.addHandler(handler)
Example #28
Source File: logging.py From lxdock with GNU General Public License v3.0 | 5 votes |
def get_per_container_formatter(container_name): """ Returns a logging formatter which prefixes each message with a container name. """ return ColoredFormatter( '%(log_color)s==> {name}: %(message)s'.format(name=container_name), log_colors=LOG_COLORS)
Example #29
Source File: logs.py From pyrobud with MIT License | 5 votes |
def setup_logging() -> None: """Configures the logging module with colored level and message formatting.""" logging.root.setLevel(LOG_LEVEL) formatter = colorlog.ColoredFormatter(LOG_FORMAT) stream = logging.StreamHandler() stream.setLevel(LOG_LEVEL) stream.setFormatter(formatter) root = logging.getLogger() root.setLevel(LOG_LEVEL) root.addHandler(stream)
Example #30
Source File: plogging.py From plumbery with Apache License 2.0 | 5 votes |
def __init__(self): self.logger = logging.getLogger('plumbery') self.logger.propagate = 0 # logging to console # handler = colorlog.StreamHandler() formatter = colorlog.ColoredFormatter( "%(asctime)-2s %(log_color)s%(message)s", datefmt='%H:%M:%S', reset=True, log_colors={ 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red,bg_white', }, secondary_log_colors={}, style='%' ) handler.setFormatter(formatter) self.logger.addHandler(handler) logging.getLogger('paramiko.transport').addHandler(handler) logging.getLogger('paramiko.transport').propagate = 0 self.reset()