Source code for errbot.logs
import inspect
import logging
import sys
from typing import Optional
COLORS = {
"DEBUG": "cyan",
"INFO": "green",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "red",
}
NO_COLORS = {
"DEBUG": "",
"INFO": "",
"WARNING": "",
"ERROR": "",
"CRITICAL": "",
}
[docs]
def ispydevd():
for frame in inspect.stack():
if frame[1].endswith("pydevd.py"):
return True
return False
root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO)
pydev = ispydevd()
stream = sys.stdout if pydev else sys.stderr
isatty = (
pydev or stream.isatty()
) # force isatty if we are under pydev because it supports coloring anyway.
console_hdlr = logging.StreamHandler(stream)
[docs]
def get_log_colors(theme_color: Optional[str] = None) -> str:
"""Return a tuple containing the log format string and a log color dict"""
if theme_color == "light":
text_color_theme = "white"
elif theme_color == "dark":
text_color_theme = "black"
else: # Anything else produces nocolor
return "%(name)-25.25s%(reset)s %(message)s%(reset)s", NO_COLORS
return f"%(name)-25.25s%(reset)s %({text_color_theme})s%(message)s%(reset)s", COLORS