From 4c328370c225800b90f5bb16bc9c2d053e27595d Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 27 Feb 2024 16:33:25 +0300 Subject: [PATCH] logger-improved --- resolvers/editor.py | 2 +- services/logger.py | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/resolvers/editor.py b/resolvers/editor.py index 0a221a9e..38199b6c 100644 --- a/resolvers/editor.py +++ b/resolvers/editor.py @@ -177,7 +177,7 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False): user_id = info.context.get('user_id') if not user_id: return {"error": "unauthorized"} - roles = info.context.get('roles') + roles = info.context.get('roles', []) shout_input = shout_input or {} with local_session() as session: author = session.query(Author).filter(Author.user == user_id).first() diff --git a/services/logger.py b/services/logger.py index 2edf17ee..9ada3d65 100644 --- a/services/logger.py +++ b/services/logger.py @@ -16,10 +16,11 @@ secondary_colors = { 'asctime': {'DEBUG': 'cyan'}, 'process': {'DEBUG': 'purple'}, 'module': {'DEBUG': 'light_black,bg_blue'}, + 'funcName': {'DEBUG': 'light_white,bg_blue'}, # Add this line } # Define the log format string -fmt_string = '%(log_color)s%(levelname)s: %(log_color)s[%(module)s]%(reset)s %(white)s%(message)s' +fmt_string = '%(log_color)s%(levelname)s: %(log_color)s[%(module)s.%(funcName)s]%(reset)s %(white)s%(message)s' # Define formatting configuration fmt_config = { @@ -29,7 +30,6 @@ fmt_config = { 'reset': True, } - class MultilineColoredFormatter(colorlog.ColoredFormatter): def format(self, record): # Check if the message is multiline @@ -46,7 +46,6 @@ class MultilineColoredFormatter(colorlog.ColoredFormatter): # If not multiline or no message, use the default formatting return super().format(record) - # Create a MultilineColoredFormatter object for colorized logging formatter = MultilineColoredFormatter(fmt_string, **fmt_config) @@ -54,7 +53,6 @@ formatter = MultilineColoredFormatter(fmt_string, **fmt_config) stream = logging.StreamHandler() stream.setFormatter(formatter) - def get_colorful_logger(name='main'): # Create and configure the logger logger = logging.getLogger(name) @@ -63,7 +61,6 @@ def get_colorful_logger(name='main'): return logger - # Set up the root logger with the same formatting root_logger = logging.getLogger() root_logger.setLevel(logging.DEBUG)