marmot.utils.loggersetup.SetupLogger#

class SetupLogger(logger_type: str, log_directory: pathlib.Path = WindowsPath('C:/Users/dlevie/Documents/Marmot/logs'), log_suffix: Optional[str] = None, **kwargs)[source]#

Bases: object

Sets up the python logger.

This class handles the following.

  1. Configures logger from LOG_CONFIG_FILE file or DEFAULT_LOG_CONFIG.

  2. Handles rollover of log file on each instantiation.

  3. Sets log_directory.

  4. Append optional suffix to the end of the log file name

Optional suffix is useful when running multiple processes in parallel to allow logging to separate files.

Parameters
  • logger_type (str) – Type of logger defined in ‘utils/marmot_logging_config.yml’

  • log_directory (Path, optional) – log directory to save logs. Defaults to LOG_DIR.

  • log_suffix (str, optional) – Optional suffix to add to end of log file. Defaults to None.

Methods

Attributes

DEFAULT_LOG_CONFIG

Default log config if LOG_CONFIG_FILE cannot be found

LOG_CONFIG_FILE

Name of default logging config file located in utils package

LOG_CONFIG_FILE: str = 'marmot_logging_config.yml'#

Name of default logging config file located in utils package

DEFAULT_LOG_CONFIG: dict = {'formatters': {'info_format': {'datefmt': '%Y-%m-%d %H:%M:%S', 'format': '%(asctime)s:%(levelname)-8s- %(message)s'}, 'warning_format': {'datefmt': '%Y-%m-%d %H:%M:%S', 'format': '%(asctime)s:%(levelname)s:%(module)s.%(funcName)s - %(message)s'}}, 'handlers': {'console': {'class': 'logging.StreamHandler', 'level': 'INFO', 'stream': 'ext://sys.stdout'}, 'info_handler': {'backupCount': 3, 'class': 'logging.handlers.RotatingFileHandler', 'encoding': 'utf8', 'filename': '{}/Log_{}{}.log', 'formatter': 'info_format', 'level': 'INFO', 'mode': 'a'}, 'warning_handler': {'backupCount': 3, 'class': 'logging.handlers.RotatingFileHandler', 'encoding': 'utf8', 'filename': '{}/WARNINGS_{}{}.log', 'formatter': 'warning_format', 'level': 'WARNING', 'mode': 'a'}}, 'loggers': {'formatter': {'handlers': ['console', 'warning_handler', 'info_handler'], 'level': 'INFO', 'propagate': True}, 'plotter': {'handlers': ['console', 'warning_handler', 'info_handler'], 'level': 'INFO', 'propagate': True}, 'root': {'handlers': ['console'], 'level': 'DEBUG'}}, 'version': 1}#

Default log config if LOG_CONFIG_FILE cannot be found