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)