Skip to content

Commit

Permalink
Fixes for lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Chsudeepta authored and Chsudeepta committed Oct 16, 2024
1 parent 6cae0a2 commit 9724796
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
23 changes: 11 additions & 12 deletions src/ibex_bluesky_core/logger/logger.py
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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')

22 changes: 10 additions & 12 deletions tests/logger/test_logger.py
Original file line number Diff line number Diff line change
@@ -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


assert loghandler is not None
assert loghandler.name == 'timedRotatingFileHandler'
assert loghandler.when.lower() == 'midnight'
assert loghandler.baseFilename.endswith(LOG_FILE_NAME)

0 comments on commit 9724796

Please sign in to comment.