Skip to content

Instantly share code, notes, and snippets.

@a-recknagel
Last active May 18, 2021 12:08
Show Gist options
  • Save a-recknagel/238cd768ccbac31c98d2118834788f06 to your computer and use it in GitHub Desktop.
Save a-recknagel/238cd768ccbac31c98d2118834788f06 to your computer and use it in GitHub Desktop.
qlog test
from logging import getLogger, config
from colorama import Fore, Back, Style
log = getLogger(__name__)
config.dictConfig(
{
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"qlog": {
"()": "qlogging.qlogging.ColoredFormatter",
"colors": {
'DEBUG': Fore.CYAN + Style.BRIGHT,
'INFO': Fore.GREEN + Style.BRIGHT,
'WARNING': Fore.YELLOW + Style.BRIGHT,
'ERROR': Fore.RED + Style.BRIGHT,
'CRITICAL': Fore.RED + Back.WHITE + Style.BRIGHT,
},
"format": "%(color)s%(asctime)s [%(levelname)s] %(name)s: %(message)s"
},
},
"handlers": {
"console": {
"level": "DEBUG",
"formatter": "qlog",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
},
},
"loggers": {
"": {
"handlers": ["console"],
"level": "DEBUG",
"propagate": True,
},
},
}
)
# colored output, since I adapted the format string
log.debug("test 1")
log.info("test 2")
log.warning("test 3")
log.error("test 4")
@ELHoussineT
Copy link

just make sure you update to latest qlogger by: pip3 install qlogging>=1.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment