idmtools.core.logging module#
idmtools logging module.
We configure our logging here, manage multi-process logging, alternate logging level, and additional utilities to manage logging.
Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.
- class idmtools.core.logging.IdmToolsLoggingConfig(level: str | int = 30, filename: str | None = 'idmtools.log', console: bool = False, file_level: str | int = 'DEBUG', force: bool = False, file_log_format_str: str | None = None, user_log_format_str: str = '%(message)s', use_colored_logs: bool = True, user_output: bool = True, enable_file_logging: str | bool = True)[source]#
Bases:
object
Defines the config options available for idmtools logs.
- file_log_format_str: str = None#
//docs.python.org/3/library/logging.html#logrecord-attributes for format vars
- Type:
File format string. See https
- user_log_format_str: str = '%(message)s'#
//docs.python.org/3/library/logging.html#logrecord-attributes for format vars
- Type:
Logging format. See https
- user_output: bool = True#
Toggle user output. This should only be used in certain situations like CLI’s that output JSON
- __init__(level: str | int = 30, filename: str | None = 'idmtools.log', console: bool = False, file_level: str | int = 'DEBUG', force: bool = False, file_log_format_str: str | None = None, user_log_format_str: str = '%(message)s', use_colored_logs: bool = True, user_output: bool = True, enable_file_logging: str | bool = True) None #
- class idmtools.core.logging.MultiProcessSafeRotatingFileHandler(filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=False)[source]#
Bases:
RotatingFileHandler
Multi-process safe logger.
- __init__(filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=False)[source]#
See RotatingFileHandler for full details on arguments.
- Parameters:
filename – Filename to use
mode – Mode
maxBytes – Max bytes
backupCount – Total backups
encoding – Encoding
delay – Delay
- class idmtools.core.logging.PrintHandler(level=0)[source]#
Bases:
Handler
A simple print handler. Used in cases where logging fails.
- idmtools.core.logging.setup_logging(logging_config: IdmToolsLoggingConfig) None [source]#
Set up logging.
- Parameters:
logging_config – IdmToolsLoggingConfig that defines our config
- Returns:
Returns None
See also
For logging levels, see https://coloredlogs.readthedocs.io/en/latest/api.html#id26
- idmtools.core.logging.setup_handlers(logging_config: IdmToolsLoggingConfig)[source]#
Setup Handlers for Global and user Loggers.
- Parameters:
logging_config – Logging config
- Returns:
FileHandler or None
- idmtools.core.logging.setup_user_logger(logging_config: IdmToolsLoggingConfig)[source]#
Setup the user logger. This logger is meant for user output only.
- Parameters:
logging_config – Logging config object.
- Returns:
None
- idmtools.core.logging.setup_user_print_logger()[source]#
Setup a print based logger for user messages.
- Returns:
None
- idmtools.core.logging.set_file_logging(logging_config: IdmToolsLoggingConfig, formatter: Formatter)[source]#
Set File Logging.
- Parameters:
logging_config – Logging config object.
formatter – Formatter obj
- Returns:
Return File handler
- idmtools.core.logging.create_file_handler(file_level, formatter: Formatter, filename: str)[source]#
Create a MultiProcessSafeRotatingFileHandler for idmtools.log.
- Parameters:
file_level – Level to log to file
formatter – Formatter to set on the handler
filename – Filename to use
- Returns:
SafeRotatingFileHandler with properties provided