|
import logging |
|
import copy |
|
import sys |
|
|
|
from modules import shared |
|
from scripts.globals import IS_RUN |
|
|
|
|
|
class ColoredFormatter(logging.Formatter): |
|
COLORS = { |
|
"DEBUG": "\033[0;36m", |
|
"STATUS": "\033[38;5;173m", |
|
"INFO": "\033[0;32m", |
|
"WARNING": "\033[0;33m", |
|
"ERROR": "\033[0;31m", |
|
"CRITICAL": "\033[0;37;41m", |
|
"RESET": "\033[0m", |
|
} |
|
|
|
def format(self, record): |
|
colored_record = copy.copy(record) |
|
levelname = colored_record.levelname |
|
seq = self.COLORS.get(levelname, self.COLORS["RESET"]) |
|
colored_record.levelname = f"{seq}{levelname}{self.COLORS['RESET']}" |
|
return super().format(colored_record) |
|
|
|
|
|
|
|
logger = logging.getLogger("ReActor") |
|
logger.propagate = False |
|
|
|
|
|
logging.addLevelName(logging.INFO, "STATUS") |
|
|
|
|
|
if not logger.handlers: |
|
handler = logging.StreamHandler(sys.stdout) |
|
handler.setFormatter( |
|
ColoredFormatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s","%H:%M:%S") |
|
) |
|
logger.addHandler(handler) |
|
|
|
|
|
loglevel_string = getattr(shared.cmd_opts, "reactor_loglevel", "INFO") |
|
loglevel = getattr(logging, loglevel_string.upper(), "info") |
|
logger.setLevel(loglevel) |
|
|
|
def set_Run(value): |
|
global IS_RUN |
|
IS_RUN = value |
|
|
|
def get_Run(): |
|
global IS_RUN |
|
return IS_RUN |
|
|