From 2682a3978b5100a555cfca10ddd7d0296ed842a3 Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Fri, 11 Oct 2024 14:39:15 +0100 Subject: [PATCH 01/17] Added logger --- src/ibex_bluesky_core/logger/logger.py | 34 +++++++++++++++++++++++ src/ibex_bluesky_core/logger/logging.conf | 25 +++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/ibex_bluesky_core/logger/logger.py create mode 100644 src/ibex_bluesky_core/logger/logging.conf diff --git a/src/ibex_bluesky_core/logger/logger.py b/src/ibex_bluesky_core/logger/logger.py new file mode 100644 index 0000000..e2a36d0 --- /dev/null +++ b/src/ibex_bluesky_core/logger/logger.py @@ -0,0 +1,34 @@ +# ***************************************************************************** +# Bluesky specific logging utility. +# ***************************************************************************** + +import os, logging, logging.config +import logging.handlers +from logging.handlers import TimedRotatingFileHandler +from bluesky.log import config_bluesky_logging +import pathlib + +BLUESKY_LOGGER = 'bluesky' +DEFAULT_LOGGER = 'blueskylogs.log' +LOG_FOLDER = os.path.join("C:\\", "instrument", "var", "logs", BLUESKY_LOGGER) + +# Find the log directory, if already set in the environment, else use the default +log_location = os.environ.get("BLUESKY_LOGS", LOG_FOLDER) +# Make the log directory if it doesn't already exist +os.makedirs(log_location, exist_ok = True) + +filepath = pathlib.Path(__file__).resolve().parent +#disable_existing_loggers ensures all loggers have same configuration as below +logging.config.fileConfig(os.path.join(filepath, 'logging.conf'), disable_existing_loggers=False) + +blueskylogger = logging.getLogger('root') + +#This code only needed if disable_existing_loggers is removed from above and only chosen loggers are to be share the handler +#logging.config.fileConfig(os.path.join(filepath, 'logging.conf')) +# +#for handler in blueskylogger.handlers: +# if isinstance(handler, logging.handlers.TimedRotatingFileHandler): +# logger = logging.getLogger(BLUESKY_LOGGER) +# if not logger.handlers: +# logger.addHandler(handler) + diff --git a/src/ibex_bluesky_core/logger/logging.conf b/src/ibex_bluesky_core/logger/logging.conf new file mode 100644 index 0000000..a264de4 --- /dev/null +++ b/src/ibex_bluesky_core/logger/logging.conf @@ -0,0 +1,25 @@ +[loggers] +keys=root + +[handlers] +keys=timedRotatingFileHandler + +[formatters] +keys=simpleFormatter,debugFormatter + +[logger_root] +level=INFO +handlers=timedRotatingFileHandler + +[handler_timedRotatingFileHandler] +class=logging.handlers.TimedRotatingFileHandler +level=INFO +formatter=debugFormatter +#args=(os.path.join("C:\\", "instrument", "var", "logs", "bluesky", "blueskylogs.log"), "midnight") +args=(os.path.join(os.environ.get("BLUESKY_LOGS", os.path.join("C:\\", "instrument", "var", "logs", "bluesky")),'blueskylogs.log'), "midnight") + +[formatter_simpleFormatter] +format=%(asctime)s - %(name)s - %(levelname)s - %(message)s + +[formatter_debugFormatter] +format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s From 7c0e4780ec793bc39801b9d3d385a18d416717ba Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Mon, 14 Oct 2024 14:26:58 +0100 Subject: [PATCH 02/17] Logging changes --- src/ibex_bluesky_core/logger/logger.py | 15 +++++++++------ src/ibex_bluesky_core/logger/logging.conf | 10 ++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ibex_bluesky_core/logger/logger.py b/src/ibex_bluesky_core/logger/logger.py index e2a36d0..77525ab 100644 --- a/src/ibex_bluesky_core/logger/logger.py +++ b/src/ibex_bluesky_core/logger/logger.py @@ -1,11 +1,13 @@ # ***************************************************************************** # Bluesky specific logging utility. +# To use me +# 1. you need to import me --> from ibex_bluesky_core.logger import logger +# 2. Use me at the level you want --> logger.blueskylogger.info("Some useless message") +# 3. To change the log level check the logging.conf file # ***************************************************************************** import os, logging, logging.config import logging.handlers -from logging.handlers import TimedRotatingFileHandler -from bluesky.log import config_bluesky_logging import pathlib BLUESKY_LOGGER = 'bluesky' @@ -14,18 +16,19 @@ # Find the log directory, if already set in the environment, else use the default log_location = os.environ.get("BLUESKY_LOGS", LOG_FOLDER) -# Make the log directory if it doesn't already exist +# Create the log directory if it doesn't already exist os.makedirs(log_location, exist_ok = True) filepath = pathlib.Path(__file__).resolve().parent #disable_existing_loggers ensures all loggers have same configuration as below logging.config.fileConfig(os.path.join(filepath, 'logging.conf'), disable_existing_loggers=False) -blueskylogger = logging.getLogger('root') +blueskylogger = logging.getLogger('blueskycore') -#This code only needed if disable_existing_loggers is removed from above and only chosen loggers are to be share the handler -#logging.config.fileConfig(os.path.join(filepath, 'logging.conf')) +#This code or an adapted version is only needed if only specific loggers are to share the handler: # +# 1. Remove disable_existing_loggers or set to True ==> logging.config.fileConfig(os.path.join(filepath, 'logging.conf')) +#from bluesky.log import config_bluesky_logging #for handler in blueskylogger.handlers: # if isinstance(handler, logging.handlers.TimedRotatingFileHandler): # logger = logging.getLogger(BLUESKY_LOGGER) diff --git a/src/ibex_bluesky_core/logger/logging.conf b/src/ibex_bluesky_core/logger/logging.conf index a264de4..af33c17 100644 --- a/src/ibex_bluesky_core/logger/logging.conf +++ b/src/ibex_bluesky_core/logger/logging.conf @@ -1,5 +1,5 @@ [loggers] -keys=root +keys=root,blueskycore [handlers] keys=timedRotatingFileHandler @@ -11,11 +11,17 @@ keys=simpleFormatter,debugFormatter level=INFO handlers=timedRotatingFileHandler +[logger_blueskycore] +level=INFO +qualname=blueskycore +propagate=0 +handlers=timedRotatingFileHandler + [handler_timedRotatingFileHandler] class=logging.handlers.TimedRotatingFileHandler level=INFO formatter=debugFormatter -#args=(os.path.join("C:\\", "instrument", "var", "logs", "bluesky", "blueskylogs.log"), "midnight") +#args=set the file name to blueskylogs.log and the log folder as set in the environment variable; if not set, set to default - \instrument\var\logs\bluesky args=(os.path.join(os.environ.get("BLUESKY_LOGS", os.path.join("C:\\", "instrument", "var", "logs", "bluesky")),'blueskylogs.log'), "midnight") [formatter_simpleFormatter] From 9c1f6c979358609cd36a03701453361ca1605a0d Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Tue, 15 Oct 2024 13:48:07 +0100 Subject: [PATCH 03/17] Addded unit tests --- tests/logger/test_logger.py | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/logger/test_logger.py diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py new file mode 100644 index 0000000..c106005 --- /dev/null +++ b/tests/logger/test_logger.py @@ -0,0 +1,50 @@ +import os, sys +from ibex_bluesky_core.logger import logger + +LOG_FOLDER = os.path.join("C:\\", "instrument", "var", "logs", "bluesky") +LOG_MESSAGE = "Logging something to test" +LOG_ENV_PATH = "BLUESKY_LOGS" +LOG_FILE_NAME = "blueskylogs.log" + +def test_GIVEN_logging_is_requested_THEN_the_log_folder_exists(): + this_function_name = sys._getframe( ).f_code.co_name + message = LOG_MESSAGE + this_function_name + # Log invocation. + logger.blueskylogger.info(message); + + if (os.environ.__contains__(LOG_ENV_PATH)): + assert os.path.exists(os.environ[LOG_ENV_PATH]) == False + + if (not os.environ.__contains__(LOG_ENV_PATH)): + assert os.path.exists(LOG_FOLDER) == True + +def test_GIVEN_logging_is_requested_THEN_the_log_file_exists(): + log_path = LOG_FOLDER + if (os.environ.__contains__(LOG_ENV_PATH)): + log_path = os.environ[LOG_ENV_PATH] + + # Log invocation. + this_function_name = sys._getframe( ).f_code.co_name + message = LOG_MESSAGE + this_function_name + logger.blueskylogger.info(message); + + qualified_log_filename = os.path.join(log_path, LOG_FILE_NAME) + assert os.path.exists(qualified_log_filename) == True + +def test_GIVEN_logging_is_requested_THEN_the_log_file_contains_the_message(): + log_path = LOG_FOLDER + if (os.environ.__contains__(LOG_ENV_PATH)): + log_path = os.environ[LOG_ENV_PATH] + + # Log invocation. + this_function_name = sys._getframe( ).f_code.co_name + message = LOG_MESSAGE + this_function_name + logger.blueskylogger.info(message); + + qualified_log_filename = os.path.join(log_path, LOG_FILE_NAME) + assert os.path.exists(qualified_log_filename) == True + # Open the log file and read its content. + with open(qualified_log_filename, 'r') as f: + content = f.read() + assert content.__contains__(message); + From b3780030f13bfd6f392c02226a222ea160ea5247 Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Tue, 15 Oct 2024 16:51:56 +0100 Subject: [PATCH 04/17] Added tests for the handler --- tests/logger/test_logger.py | 44 +++++++++++-------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py index c106005..890c0cb 100644 --- a/tests/logger/test_logger.py +++ b/tests/logger/test_logger.py @@ -1,50 +1,32 @@ import os, sys +import logging from ibex_bluesky_core.logger import logger LOG_FOLDER = os.path.join("C:\\", "instrument", "var", "logs", "bluesky") -LOG_MESSAGE = "Logging something to test" +LOG_MESSAGE = "Logging something to " LOG_ENV_PATH = "BLUESKY_LOGS" LOG_FILE_NAME = "blueskylogs.log" -def test_GIVEN_logging_is_requested_THEN_the_log_folder_exists(): +def test_GIVEN_logging_is_requested_THEN_handler_is_added(): this_function_name = sys._getframe( ).f_code.co_name message = LOG_MESSAGE + this_function_name # Log invocation. logger.blueskylogger.info(message); - if (os.environ.__contains__(LOG_ENV_PATH)): - assert os.path.exists(os.environ[LOG_ENV_PATH]) == False - - if (not os.environ.__contains__(LOG_ENV_PATH)): - assert os.path.exists(LOG_FOLDER) == True + logHandler = None + for handler in logger.blueskylogger.handlers: + if isinstance(handler, logging.handlers.TimedRotatingFileHandler): + logHandler = handler -def test_GIVEN_logging_is_requested_THEN_the_log_file_exists(): - log_path = LOG_FOLDER - if (os.environ.__contains__(LOG_ENV_PATH)): - log_path = os.environ[LOG_ENV_PATH] + assert handler is not None + assert handler.name == 'timedRotatingFileHandler' + assert handler.when.lower() == 'midnight' + assert handler.baseFilename.endswith(LOG_FILE_NAME) == True + + - # Log invocation. - this_function_name = sys._getframe( ).f_code.co_name - message = LOG_MESSAGE + this_function_name - logger.blueskylogger.info(message); - qualified_log_filename = os.path.join(log_path, LOG_FILE_NAME) - assert os.path.exists(qualified_log_filename) == True -def test_GIVEN_logging_is_requested_THEN_the_log_file_contains_the_message(): - log_path = LOG_FOLDER - if (os.environ.__contains__(LOG_ENV_PATH)): - log_path = os.environ[LOG_ENV_PATH] - # Log invocation. - this_function_name = sys._getframe( ).f_code.co_name - message = LOG_MESSAGE + this_function_name - logger.blueskylogger.info(message); - qualified_log_filename = os.path.join(log_path, LOG_FILE_NAME) - assert os.path.exists(qualified_log_filename) == True - # Open the log file and read its content. - with open(qualified_log_filename, 'r') as f: - content = f.read() - assert content.__contains__(message); From c5f609b458b2d81f9f3919f2f46f2eedd8e6973c Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Wed, 16 Oct 2024 16:30:33 +0100 Subject: [PATCH 05/17] Removed commented codes --- src/ibex_bluesky_core/logger/logger.py | 10 ---------- tests/logger/test_logger.py | 8 +------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/ibex_bluesky_core/logger/logger.py b/src/ibex_bluesky_core/logger/logger.py index 77525ab..901e00a 100644 --- a/src/ibex_bluesky_core/logger/logger.py +++ b/src/ibex_bluesky_core/logger/logger.py @@ -25,13 +25,3 @@ blueskylogger = logging.getLogger('blueskycore') -#This code or an adapted version is only needed if only specific loggers are to share the handler: -# -# 1. Remove disable_existing_loggers or set to True ==> logging.config.fileConfig(os.path.join(filepath, 'logging.conf')) -#from bluesky.log import config_bluesky_logging -#for handler in blueskylogger.handlers: -# if isinstance(handler, logging.handlers.TimedRotatingFileHandler): -# logger = logging.getLogger(BLUESKY_LOGGER) -# if not logger.handlers: -# logger.addHandler(handler) - diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py index 890c0cb..29263dd 100644 --- a/tests/logger/test_logger.py +++ b/tests/logger/test_logger.py @@ -23,10 +23,4 @@ def test_GIVEN_logging_is_requested_THEN_handler_is_added(): assert handler.when.lower() == 'midnight' assert handler.baseFilename.endswith(LOG_FILE_NAME) == True - - - - - - - + \ No newline at end of file From 59d101107bc592c26034ac34fb4dc13a845750d1 Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Wed, 16 Oct 2024 17:06:04 +0100 Subject: [PATCH 06/17] Documentation for logger --- doc/logging/logger.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 doc/logging/logger.md diff --git a/doc/logging/logger.md b/doc/logging/logger.md new file mode 100644 index 0000000..c7d9365 --- /dev/null +++ b/doc/logging/logger.md @@ -0,0 +1,7 @@ +# Bluesky logger + +To invoke the bluesky logger, import as `from ibex_bluesky_core.logger import logger` and use it at the desired level: +`logger.blueskylogger.warning("Message to be logged")` +The logger utilizes a `TimedRotatingFileHandler` defined in the `logging.conf` file that rolls over the log at midnight. + +The default logging level is defined at `INFO`. From 9724796eef24bc87d15007e54cf79db883070176 Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Wed, 16 Oct 2024 19:14:29 +0100 Subject: [PATCH 07/17] Fixes for lint issues --- src/ibex_bluesky_core/logger/logger.py | 23 +++++++++++------------ tests/logger/test_logger.py | 22 ++++++++++------------ 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/ibex_bluesky_core/logger/logger.py b/src/ibex_bluesky_core/logger/logger.py index 901e00a..127846e 100644 --- a/src/ibex_bluesky_core/logger/logger.py +++ b/src/ibex_bluesky_core/logger/logger.py @@ -1,14 +1,14 @@ -# ***************************************************************************** -# Bluesky specific logging utility. -# To use me -# 1. you need to import me --> from ibex_bluesky_core.logger import logger -# 2. Use me at the level you want --> logger.blueskylogger.info("Some useless message") -# 3. To change the log level check the logging.conf file -# ***************************************************************************** +"""Bluesky specific logging utility.""" +import logging +import logging.config +import os +from pathlib import Path -import os, logging, logging.config -import logging.handlers -import pathlib +"""Logger for bluesky. Loads the configured log handler and also attaches to default bluesky logger +To use me +1. you need to import me --> from ibex_bluesky_core.logger import logger +2. Use me at the level you want --> logger.blueskylogger.info("Some useful message") +3. To change the log level check the logging.conf file""" BLUESKY_LOGGER = 'bluesky' DEFAULT_LOGGER = 'blueskylogs.log' @@ -19,9 +19,8 @@ # Create the log directory if it doesn't already exist os.makedirs(log_location, exist_ok = True) -filepath = pathlib.Path(__file__).resolve().parent +filepath = Path(__file__).resolve().parent #disable_existing_loggers ensures all loggers have same configuration as below logging.config.fileConfig(os.path.join(filepath, 'logging.conf'), disable_existing_loggers=False) blueskylogger = logging.getLogger('blueskycore') - diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py index 29263dd..6c66bf7 100644 --- a/tests/logger/test_logger.py +++ b/tests/logger/test_logger.py @@ -1,26 +1,24 @@ -import os, sys + import logging +import sys + from ibex_bluesky_core.logger import logger -LOG_FOLDER = os.path.join("C:\\", "instrument", "var", "logs", "bluesky") LOG_MESSAGE = "Logging something to " -LOG_ENV_PATH = "BLUESKY_LOGS" LOG_FILE_NAME = "blueskylogs.log" def test_GIVEN_logging_is_requested_THEN_handler_is_added(): this_function_name = sys._getframe( ).f_code.co_name message = LOG_MESSAGE + this_function_name # Log invocation. - logger.blueskylogger.info(message); + logger.blueskylogger.info(message) - logHandler = None + loghandler = None for handler in logger.blueskylogger.handlers: if isinstance(handler, logging.handlers.TimedRotatingFileHandler): - logHandler = handler - - assert handler is not None - assert handler.name == 'timedRotatingFileHandler' - assert handler.when.lower() == 'midnight' - assert handler.baseFilename.endswith(LOG_FILE_NAME) == True + loghandler = handler - \ No newline at end of file + assert loghandler is not None + assert loghandler.name == 'timedRotatingFileHandler' + assert loghandler.when.lower() == 'midnight' + assert loghandler.baseFilename.endswith(LOG_FILE_NAME) From cd33ec515c2dab175cdfef91f6586bae7aea7fa6 Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Thu, 17 Oct 2024 12:48:22 +0100 Subject: [PATCH 08/17] Ruff reformatting done --- src/ibex_bluesky_core/logger/logger.py | 13 +++++++------ tests/logger/test_logger.py | 8 ++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ibex_bluesky_core/logger/logger.py b/src/ibex_bluesky_core/logger/logger.py index 127846e..4f75461 100644 --- a/src/ibex_bluesky_core/logger/logger.py +++ b/src/ibex_bluesky_core/logger/logger.py @@ -1,4 +1,5 @@ """Bluesky specific logging utility.""" + import logging import logging.config import os @@ -10,17 +11,17 @@ 2. Use me at the level you want --> logger.blueskylogger.info("Some useful message") 3. To change the log level check the logging.conf file""" -BLUESKY_LOGGER = 'bluesky' -DEFAULT_LOGGER = 'blueskylogs.log' +BLUESKY_LOGGER = "bluesky" +DEFAULT_LOGGER = "blueskylogs.log" LOG_FOLDER = os.path.join("C:\\", "instrument", "var", "logs", BLUESKY_LOGGER) # Find the log directory, if already set in the environment, else use the default log_location = os.environ.get("BLUESKY_LOGS", LOG_FOLDER) # Create the log directory if it doesn't already exist -os.makedirs(log_location, exist_ok = True) +os.makedirs(log_location, exist_ok=True) filepath = Path(__file__).resolve().parent -#disable_existing_loggers ensures all loggers have same configuration as below -logging.config.fileConfig(os.path.join(filepath, 'logging.conf'), disable_existing_loggers=False) +# disable_existing_loggers ensures all loggers have same configuration as below +logging.config.fileConfig(os.path.join(filepath, "logging.conf"), disable_existing_loggers=False) -blueskylogger = logging.getLogger('blueskycore') +blueskylogger = logging.getLogger("blueskycore") diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py index 6c66bf7..a4f0007 100644 --- a/tests/logger/test_logger.py +++ b/tests/logger/test_logger.py @@ -1,4 +1,3 @@ - import logging import sys @@ -7,8 +6,9 @@ LOG_MESSAGE = "Logging something to " LOG_FILE_NAME = "blueskylogs.log" + def test_GIVEN_logging_is_requested_THEN_handler_is_added(): - this_function_name = sys._getframe( ).f_code.co_name + this_function_name = sys._getframe().f_code.co_name message = LOG_MESSAGE + this_function_name # Log invocation. logger.blueskylogger.info(message) @@ -19,6 +19,6 @@ def test_GIVEN_logging_is_requested_THEN_handler_is_added(): loghandler = handler assert loghandler is not None - assert loghandler.name == 'timedRotatingFileHandler' - assert loghandler.when.lower() == 'midnight' + assert loghandler.name == "timedRotatingFileHandler" + assert loghandler.when.lower() == "midnight" assert loghandler.baseFilename.endswith(LOG_FILE_NAME) From 3a396430d015994c13fa894c916cb56a5aa20e5e Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Thu, 17 Oct 2024 12:54:25 +0100 Subject: [PATCH 09/17] added asssert to check type --- tests/logger/test_logger.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py index a4f0007..05754f4 100644 --- a/tests/logger/test_logger.py +++ b/tests/logger/test_logger.py @@ -18,6 +18,7 @@ def test_GIVEN_logging_is_requested_THEN_handler_is_added(): if isinstance(handler, logging.handlers.TimedRotatingFileHandler): loghandler = handler + assert isinstance(handler, logging.handlers.TimedRotatingFileHandler) assert loghandler is not None assert loghandler.name == "timedRotatingFileHandler" assert loghandler.when.lower() == "midnight" From e91dbd9cf884d3b41f30790896ed99bbb4e939be Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Thu, 17 Oct 2024 13:00:31 +0100 Subject: [PATCH 10/17] added asssert to check type --- tests/logger/test_logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py index 05754f4..b0cb41f 100644 --- a/tests/logger/test_logger.py +++ b/tests/logger/test_logger.py @@ -18,7 +18,7 @@ def test_GIVEN_logging_is_requested_THEN_handler_is_added(): if isinstance(handler, logging.handlers.TimedRotatingFileHandler): loghandler = handler - assert isinstance(handler, logging.handlers.TimedRotatingFileHandler) + assert isinstance(loghandler, logging.handlers.TimedRotatingFileHandler) assert loghandler is not None assert loghandler.name == "timedRotatingFileHandler" assert loghandler.when.lower() == "midnight" From c7c1342d62eaeba55f4e986a5ca10b3b0b975332 Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Thu, 17 Oct 2024 13:03:03 +0100 Subject: [PATCH 11/17] added asssert to check type --- tests/logger/test_logger.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py index b0cb41f..7012735 100644 --- a/tests/logger/test_logger.py +++ b/tests/logger/test_logger.py @@ -18,8 +18,8 @@ def test_GIVEN_logging_is_requested_THEN_handler_is_added(): if isinstance(handler, logging.handlers.TimedRotatingFileHandler): loghandler = handler - assert isinstance(loghandler, logging.handlers.TimedRotatingFileHandler) - assert loghandler is not None - assert loghandler.name == "timedRotatingFileHandler" - assert loghandler.when.lower() == "midnight" - assert loghandler.baseFilename.endswith(LOG_FILE_NAME) + if (isinstance(loghandler, logging.handlers.TimedRotatingFileHandler)): + assert loghandler is not None + assert loghandler.name == "timedRotatingFileHandler" + assert loghandler.when.lower() == "midnight" + assert loghandler.baseFilename.endswith(LOG_FILE_NAME) From b6f0e9a6fe417e81b4729e83f1a512fd5d992444 Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Thu, 17 Oct 2024 13:06:50 +0100 Subject: [PATCH 12/17] Ruff reformatting --- tests/logger/test_logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py index 7012735..11b5c37 100644 --- a/tests/logger/test_logger.py +++ b/tests/logger/test_logger.py @@ -18,7 +18,7 @@ def test_GIVEN_logging_is_requested_THEN_handler_is_added(): if isinstance(handler, logging.handlers.TimedRotatingFileHandler): loghandler = handler - if (isinstance(loghandler, logging.handlers.TimedRotatingFileHandler)): + if isinstance(loghandler, logging.handlers.TimedRotatingFileHandler): assert loghandler is not None assert loghandler.name == "timedRotatingFileHandler" assert loghandler.when.lower() == "midnight" From e5398299e5c14bb2a9f0c37a12e68650ea5da526 Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Thu, 17 Oct 2024 13:24:38 +0100 Subject: [PATCH 13/17] Satiate pyright --- tests/logger/test_logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py index 11b5c37..c1c61f2 100644 --- a/tests/logger/test_logger.py +++ b/tests/logger/test_logger.py @@ -18,7 +18,7 @@ def test_GIVEN_logging_is_requested_THEN_handler_is_added(): if isinstance(handler, logging.handlers.TimedRotatingFileHandler): loghandler = handler - if isinstance(loghandler, logging.handlers.TimedRotatingFileHandler): + if isinstance(loghandler, logging.FileHandler): assert loghandler is not None assert loghandler.name == "timedRotatingFileHandler" assert loghandler.when.lower() == "midnight" From 1da8554ef8d18f328458314148586960a30430db Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Thu, 17 Oct 2024 13:29:15 +0100 Subject: [PATCH 14/17] Satiate pyright --- tests/logger/test_logger.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py index c1c61f2..d15981f 100644 --- a/tests/logger/test_logger.py +++ b/tests/logger/test_logger.py @@ -18,8 +18,11 @@ def test_GIVEN_logging_is_requested_THEN_handler_is_added(): if isinstance(handler, logging.handlers.TimedRotatingFileHandler): loghandler = handler + assert isinstance(loghandler, logging.handlers.TimedRotatingFileHandler) if isinstance(loghandler, logging.FileHandler): assert loghandler is not None assert loghandler.name == "timedRotatingFileHandler" - assert loghandler.when.lower() == "midnight" assert loghandler.baseFilename.endswith(LOG_FILE_NAME) + + if isinstance(loghandler, logging.handlers.BaseRotatingHandler): + assert loghandler.when.lower() == "midnight" From 47a1c86d47138435e81a327270878f751847a4e5 Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Thu, 17 Oct 2024 15:07:57 +0100 Subject: [PATCH 15/17] satisfying pyright --- tests/logger/test_logger.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py index d15981f..a728fee 100644 --- a/tests/logger/test_logger.py +++ b/tests/logger/test_logger.py @@ -2,6 +2,7 @@ import sys from ibex_bluesky_core.logger import logger +from logging.handlers import TimedRotatingFileHandler LOG_MESSAGE = "Logging something to " LOG_FILE_NAME = "blueskylogs.log" @@ -15,14 +16,11 @@ def test_GIVEN_logging_is_requested_THEN_handler_is_added(): loghandler = None for handler in logger.blueskylogger.handlers: - if isinstance(handler, logging.handlers.TimedRotatingFileHandler): + if isinstance(handler, TimedRotatingFileHandler): loghandler = handler - assert isinstance(loghandler, logging.handlers.TimedRotatingFileHandler) - if isinstance(loghandler, logging.FileHandler): - assert loghandler is not None - assert loghandler.name == "timedRotatingFileHandler" - assert loghandler.baseFilename.endswith(LOG_FILE_NAME) - - if isinstance(loghandler, logging.handlers.BaseRotatingHandler): - assert loghandler.when.lower() == "midnight" + assert isinstance(loghandler, TimedRotatingFileHandler) + assert loghandler is not None + assert loghandler.name == "timedRotatingFileHandler" + assert loghandler.baseFilename.endswith(LOG_FILE_NAME) + assert loghandler is not None From 5ea54f7ec70de721bcba3270a0fe3abdb43cfffd Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Thu, 17 Oct 2024 15:16:59 +0100 Subject: [PATCH 16/17] Reformatted --- tests/logger/test_logger.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/logger/test_logger.py b/tests/logger/test_logger.py index a728fee..f4772fa 100644 --- a/tests/logger/test_logger.py +++ b/tests/logger/test_logger.py @@ -1,8 +1,7 @@ -import logging import sys +from logging.handlers import TimedRotatingFileHandler from ibex_bluesky_core.logger import logger -from logging.handlers import TimedRotatingFileHandler LOG_MESSAGE = "Logging something to " LOG_FILE_NAME = "blueskylogs.log" From 4697ae1d4bc9182d416cb04b409aa15aded1722b Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Mon, 28 Oct 2024 11:56:58 +0000 Subject: [PATCH 17/17] Added comments for changing the log level --- doc/logging/logger.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/logging/logger.md b/doc/logging/logger.md index c7d9365..98d0aac 100644 --- a/doc/logging/logger.md +++ b/doc/logging/logger.md @@ -4,4 +4,4 @@ To invoke the bluesky logger, import as `from ibex_bluesky_core.logger import lo `logger.blueskylogger.warning("Message to be logged")` The logger utilizes a `TimedRotatingFileHandler` defined in the `logging.conf` file that rolls over the log at midnight. -The default logging level is defined at `INFO`. +The default logging level is defined at `INFO`. This means that events of lesser severity will not be logged. To change the default level, change level attribute of logger_blueskycore in the `logging.conf`