Update to logging formatters.
This commit is contained in:
@@ -4,7 +4,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
# Version of the realpython-reader package
|
# Version of the realpython-reader package
|
||||||
__project__ = "submissions"
|
__project__ = "submissions"
|
||||||
__version__ = "202402.3b"
|
__version__ = "202402.4b"
|
||||||
__author__ = {"name":"Landon Wark", "email":"Landon.Wark@phac-aspc.gc.ca"}
|
__author__ = {"name":"Landon Wark", "email":"Landon.Wark@phac-aspc.gc.ca"}
|
||||||
__copyright__ = "2022-2024, Government of Canada"
|
__copyright__ = "2022-2024, Government of Canada"
|
||||||
|
|
||||||
|
|||||||
@@ -2285,3 +2285,4 @@ class WastewaterAssociation(SubmissionSampleAssociation):
|
|||||||
logger.error(f"Problem incrementing id: {e}")
|
logger.error(f"Problem incrementing id: {e}")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
@@ -303,6 +303,29 @@ def get_config(settings_path: Path|str|None=None) -> Settings:
|
|||||||
settings = yaml.load(stream, Loader=yaml.Loader)
|
settings = yaml.load(stream, Loader=yaml.Loader)
|
||||||
return Settings(**settings)
|
return Settings(**settings)
|
||||||
|
|
||||||
|
class CustomFormatter(logging.Formatter):
|
||||||
|
|
||||||
|
grey = "\x1b[38;20m"
|
||||||
|
yellow = "\x1b[33;20m"
|
||||||
|
red = "\x1b[31;20m"
|
||||||
|
bold_red = "\x1b[31;1m"
|
||||||
|
reset = "\x1b[0m"
|
||||||
|
# format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)"
|
||||||
|
format = "%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s"
|
||||||
|
|
||||||
|
FORMATS = {
|
||||||
|
logging.DEBUG: grey + format + reset,
|
||||||
|
logging.INFO: grey + format + reset,
|
||||||
|
logging.WARNING: yellow + format + reset,
|
||||||
|
logging.ERROR: red + format + reset,
|
||||||
|
logging.CRITICAL: bold_red + format + reset
|
||||||
|
}
|
||||||
|
|
||||||
|
def format(self, record):
|
||||||
|
log_fmt = self.FORMATS.get(record.levelno)
|
||||||
|
formatter = logging.Formatter(log_fmt)
|
||||||
|
return formatter.format(record)
|
||||||
|
|
||||||
def setup_logger(verbosity:int=3):
|
def setup_logger(verbosity:int=3):
|
||||||
"""
|
"""
|
||||||
Set logger levels using settings.
|
Set logger levels using settings.
|
||||||
@@ -337,7 +360,8 @@ def setup_logger(verbosity:int=3):
|
|||||||
ch.setLevel(logging.WARNING)
|
ch.setLevel(logging.WARNING)
|
||||||
ch.name = "Stream"
|
ch.name = "Stream"
|
||||||
# create formatter and add it to the handlers
|
# create formatter and add it to the handlers
|
||||||
formatter = logging.Formatter('%(asctime)s - %(levelname)s - {%(pathname)s:%(lineno)d} - %(message)s')
|
# formatter = logging.Formatter('%(asctime)s - %(levelname)s - {%(pathname)s:%(lineno)d} - %(message)s')
|
||||||
|
formatter = CustomFormatter()
|
||||||
fh.setFormatter(formatter)
|
fh.setFormatter(formatter)
|
||||||
ch.setFormatter(formatter)
|
ch.setFormatter(formatter)
|
||||||
# add the handlers to the logger
|
# add the handlers to the logger
|
||||||
|
|||||||
Reference in New Issue
Block a user