Logging

This module contains a function that can be used to define the default properties of the logging mechanisms used by estimationpy. There are two default loggers that log to both console and a file called estimationpy.log that will be generated in the local directory where the python interpreter is executed.

The module provides a function that takes as argument the logging levels for both the console and the log file.

If you want you can create your own configuration for the loggers without using this function. The following code snippet shows how to create a logger that uses only the console and that shows messages down to the debug level:

import logging
from logging.config import dictConfig

logging_config = dict(
      version = 1,
      formatters = {
          'f': {'format':
                '%(asctime)s | %(name)s | %(levelname)-8s | %(funcName)s | %(lineno)d | %(message)s'}
      },
      handlers = {
          'console': {
              'class': 'logging.StreamHandler',
              'formatter': 'f',
              'level': logging.DEBUG
          }
      },
      loggers = {
          'estimationpy': {
              'handlers': ['console'],
              'level': logging.DEBUG
          }
      }
  )
  
  # Configure the logger
  dictConfig(logging_config)
estimationpy.fmu_utils.estimationpy_logging.configure_logger(log_level=10, log_level_console=40, log_level_file=30)

The functions allows to configure some of the properties of the logging mechanism used by estimationpy. In particular the function allows to specify the log levels used by the different handlers implemented: one for the console and one on log files.

The levels can be defined using integers from 0 to 50, but one should used the predefined levels provided by the standard logging module. By default the console logs in ERROR mode, the file logs in WARNING mode and the overall logger in ERROR mode. See Python logging and Logging HOWTO for more information about the logging module.

The priority for the messages is

name level
CRITICAL 50
ERROR 40
WARNING 30
INFO 20
DEBUG 10

Please note that when you define a package logging level log_level equal to ERROR you implicitly prevent any log message with level lower than ERROR to be displayed or saved in the log file.

Parameters:
  • log_level (int) – Logging level for the whole package
  • log_level_console (int) – Logging level specific for the messages on the console
  • log_level_file (int) – Logging level specific for the messages in the log file