From fca5215355f69d2bff4e37f9346746132f77b4ac Mon Sep 17 00:00:00 2001 From: jleaniz Date: Thu, 8 Aug 2024 21:39:00 +0000 Subject: [PATCH] Update logger --- turbinia/config/logger.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/turbinia/config/logger.py b/turbinia/config/logger.py index 54a6a3188..cbc1e5a39 100644 --- a/turbinia/config/logger.py +++ b/turbinia/config/logger.py @@ -40,9 +40,12 @@ def setup(need_file_handler=True, need_stream_handler=True, log_file_path=None): 'ignore', 'Your application has authenticated using end user credentials') logger = logging.getLogger('turbinia') + uvicorn_error = logging.getLogger('uvicorn.error') + uvicorn_access = logging.getLogger('uvicorn.access') # Eliminate double logging from root logger logger.propagate = False - + uvicorn_error.propagate = False + uvicorn_access.propagate = False # We only need a handler if one of that type doesn't exist already if logger.handlers: for handler in logger.handlers: @@ -82,6 +85,8 @@ def setup(need_file_handler=True, need_stream_handler=True, log_file_path=None): file_handler.setFormatter(formatter) file_handler.setLevel(logging.DEBUG) logger.addHandler(file_handler) + uvicorn_error.addHandler(file_handler) + uvicorn_access.addHandler(file_handler) console_handler = logging.StreamHandler(sys.stdout) formatter = logging.Formatter( @@ -89,7 +94,8 @@ def setup(need_file_handler=True, need_stream_handler=True, log_file_path=None): console_handler.setFormatter(formatter) if need_stream_handler: logger.addHandler(console_handler) - + uvicorn_error.addHandler(console_handler) + uvicorn_access.addHandler(console_handler) # Configure the root logger to use exactly our handlers because other modules # like PSQ use this, and we want to see log messages from it when executing # from CLI. @@ -98,13 +104,8 @@ def setup(need_file_handler=True, need_stream_handler=True, log_file_path=None): root_log.removeHandler(handler) root_log.addHandler(console_handler) - # Set up uvicorn loggers - uvicron_error = logging.getLogger('uvicorn.error') - uvicorn_access = logging.getLogger('uvicorn.access') - for handler in logger.handlers: - if isinstance(handler, logging.FileHandler): - uvicron_error.addHandler(handler) - uvicorn_access.addHandler(handler) + if need_file_handler: + root_log.addHandler(file_handler) # Set filelock logging to ERROR due to log spam logging.getLogger('filelock').setLevel(logging.ERROR)