From fab94208f2eb91ab243578fc86063236f041c7db Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Sun, 8 Oct 2023 18:16:08 +0200 Subject: [PATCH] initialize logger differently --- rendercv/__init__.py | 38 ++++++++++++++++++++++++++++++++++++++ run_rendercv.py | 7 ------- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/rendercv/__init__.py b/rendercv/__init__.py index 2cbc3a7..564c9c5 100644 --- a/rendercv/__init__.py +++ b/rendercv/__init__.py @@ -2,3 +2,41 @@ r"""RenderCV package. It parses the user input YAML/JSON file and validates the data (checks spelling mistakes, checks if the dates are consistent, etc.). Then, with the data, it creates a $\LaTeX$ file and renders it with [TinyTeX](https://yihui.org/tinytex/). """ + +# initialize logging: +import logging + + +class LoggingFormatter(logging.Formatter): + """ + Logging formatter class + """ + + grey = "\x1b[38;20m" # debug level + white = "\x1b[37;20m" # info level + yellow = "\x1b[33;20m" # warning level + red = "\x1b[31;20m" # error level + bold_red = "\x1b[31;1m" # critical level + + reset = "\x1b[0m" + format = "%(levelname)s | %(message)s" + + FORMATS = { + logging.DEBUG: grey + format + reset, + logging.INFO: white + 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) + + +logger = logging.getLogger() +stdout_handler = logging.StreamHandler() +stdout_handler.setLevel(logging.INFO) +stdout_handler.setFormatter(LoggingFormatter()) +logger.addHandler(stdout_handler) \ No newline at end of file diff --git a/run_rendercv.py b/run_rendercv.py index 5154267..cfa9506 100644 --- a/run_rendercv.py +++ b/run_rendercv.py @@ -3,19 +3,12 @@ This module is a script to run the RenderCV and generate a CV as a PDF. """ import os -import logging from ruamel.yaml import YAML from rendercv.data_model import RenderCVDataModel from rendercv.rendering import render_template, run_latex -# logging config: -logging.basicConfig( - level=logging.DEBUG, - format="%(name)s - %(levelname)s - %(message)s", -) - input_name = "personal" workspace = os.path.dirname(__file__)