easy_vic_build.Logger

Logger - A Python module for configuring and managing logging.

This module provides a flexible and user-friendly interface to configure logger for Python applications. It allows users to dynamically set the logging level, format, and output destination (console or file). The module is designed to be easy to use while providing advanced customization options.

Functions

  • setup_logger: Configure the logger with user-defined settings.

Usage:

  1. Call the setup_logger to get logger instance.

  2. Use the logger method (logger.info(’…’), logger.debug(’…’)).

Example

To use the default logger configuration:
>>> from Logger import logger
>>> logger.info("This is an info message with the default setup.")
To customize the logger configuration:
>>> from Logger import setup_logger
>>> setup_logger(
...     log_level=logging.DEBUG,
...     log_format="%(asctime)s - %(levelname)s - %(message)s",
...     log_to_file=True,
...     log_file="custom_log.log"
... )
>>> logger.debug("This is a debug message with custom configuration.")

Notes

  • The default log format is “%(asctime)s - %(levelname)s - %(message)s”.

  • If no parameters are passed to setup_logger, the default configuration is used.

Dependencies

  • logging : Python standard library, Provides the core logging functionality.

Functions

setup_logger([log_level, log_format, ...])

Configure the logger with user-defined settings.

easy_vic_build.Logger.setup_logger(log_level=None, log_format=None, log_to_file=None, log_file=None)[source]

Configure the logger with user-defined settings.

This function allows users to dynamically modify the logger’s configuration, including the logging level, format, and output destination (console or file). If no parameters are provided, the default configuration is used.

Parameters:

log_levelint, optional

The logging level to set. Default is None (no change).

log_formatstr, optional

The log format to set. Default is None (no change).

log_to_filebool, optional

Whether to log to a file. Default is None (no change).

log_filestr, optional

If logging to a file, specify the file path. Default is None (no change).

Returns:

Logging.Logger

The configured logger instance.

Example:

To customize the logger configuration:
>>> setup_logger(
...     log_level=logging.DEBUG,
...     log_format="%(asctime)s - %(levelname)s - %(message)s",
...     log_to_file=True,
...     log_file="custom_log.log"
... )