Skip to content

Commit

Permalink
Refactor logger logic to use configuration from .ini file #133
Browse files Browse the repository at this point in the history
  • Loading branch information
VKTB committed Nov 4, 2024
1 parent 286c554 commit 5450937
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions scigateway_auth/common/logger_setup.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import logging.config
"""
Module for setting up and configuring the logging system.
"""

from scigateway_auth.common.config import Config, get_config_value
import logging
import logging.config
from pathlib import Path

logger_config = {
"version": 1,
"formatters": {
"default": {
"format": "[%(asctime)s] {%(module)s:%(filename)s:%(funcName)s:"
"%(lineno)d} %(levelname)s - %(message)s ",
},
},
"handlers": {
"default": {
"level": get_config_value(Config.LOG_LEVEL),
"formatter": "default",
"class": "logging.handlers.RotatingFileHandler",
"filename": get_config_value(Config.LOG_LOCATION),
"maxBytes": 5000000,
"backupCount": 10,
},
},
"root": {"level": get_config_value(Config.LOG_LEVEL), "handlers": ["default"]},
}
LOGGING_CONFIG_FILE_PATH = Path(__file__).parent.parent / "logging.ini"


def setup_logger():
logging.config.dictConfig(logger_config)
def setup_logger() -> None:
"""
Set up the logger using the configuration INI file.
"""
logging.config.fileConfig(LOGGING_CONFIG_FILE_PATH)

0 comments on commit 5450937

Please sign in to comment.