Source code for lavaflow.log

"""wxPython logging.

Defines a root logger which can be imported by scripts using this package, and
configurations for color stdout formatting. Currently, modules request loggers
locally, but they could import the root logger directly.
"""

import logging
import os
import sys

import wx
import wx.lib.newevent

import colorama
from colorama import Fore as FG, Back as BG, Style as ST

colorama.init()


# -----------------------------------------------------------------------------

# Colorama formatter

[docs]class ColoredFormatter(logging.Formatter): """Logger color formatter for changing color according to level name. """ def __init__(self, fmt=None, datefmt=None, style='%', validate=True): """ """ super().__init__(fmt, datefmt, style, validate)
[docs] def format(self, record): """Format record according to level name (standard). """ colors = { 'CRITICAL': FG.CYAN, 'ERROR': FG.RED, 'WARNING': FG.YELLOW, 'INFO': FG.WHITE, 'DEBUG': FG.GREEN, } name = record.levelname if name in colors: record.levelname = colors[name] + '[' + name + ']' + ST.RESET_ALL return logging.Formatter.format(self, record)
# Formatters color_formatter_verbose = ColoredFormatter( fmt=( FG.LIGHTBLACK_EX + '%(asctime)s ' + ST.RESET_ALL + FG.WHITE + '%(name)s ' + ST.RESET_ALL + FG.LIGHTBLUE_EX + '%(module)s.py:%(lineno)d ' + ST.RESET_ALL + '%(levelname)s ' + FG.WHITE + '%(message)s' + ST.RESET_ALL ), datefmt='%Y-%m-%d %H:%M:%S') color_formatter = ColoredFormatter( fmt=( FG.LIGHTBLACK_EX + '%(asctime)s ' + ST.RESET_ALL + '%(levelname)s ' + FG.WHITE + '%(message)s' + ST.RESET_ALL ), datefmt='%Y-%m-%d %H:%M:%S') white_formatter_verbose = logging.Formatter( fmt='%(asctime)s %(name)s %(module)s.py:%(lineno)d [%(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S') white_formatter = logging.Formatter( fmt='%(asctime)s [%(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')