-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor logger logic to use configuration from .ini file #133
- Loading branch information
Showing
1 changed file
with
12 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |