nemo_automodel.components.loggers.log_utils
#
Module Contents#
Classes#
A logging filter that controls log output based on the process rank. |
|
Logging formatter that colorizes the level name and includes date/time. |
Functions#
Logging filter to exclude WARNING level messages. |
|
Logging filter to exclude messages from specific modules. |
|
Add a filter to the root logger and all existing loggers. |
|
Ensure the root logger has at least one StreamHandler with the given formatter. |
|
Set up logging level and filters for the application. |
Data#
API#
- nemo_automodel.components.loggers.log_utils.logger#
‘getLogger(…)’
- class nemo_automodel.components.loggers.log_utils.RankFilter(name='')[source]#
Bases:
logging.Filter
A logging filter that controls log output based on the process rank.
This filter allows log messages only for rank 0 by default.
Initialization
Initialize a filter.
Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.
- nemo_automodel.components.loggers.log_utils._COLOR_RESET#
‘\x1b[0m’
- nemo_automodel.components.loggers.log_utils._LEVEL_TO_COLOR#
None
- class nemo_automodel.components.loggers.log_utils.ColorFormatter(
- fmt: str | None = None,
- datefmt: str | None = None,
- use_color: bool = True,
Bases:
logging.Formatter
Logging formatter that colorizes the level name and includes date/time.
The date is included via asctime with a default format of YYYY-MM-DD HH:MM:SS. Colors can be disabled by setting the NO_COLOR env var, or forced with FORCE_COLOR.
Initialization
Initialize the formatter with specified format strings.
Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.
Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting, :meth:
str.format
({}
) formatting or- Class:
string.Template
formatting in your format string.
.. versionchanged:: 3.2 Added the
style
parameter.
- nemo_automodel.components.loggers.log_utils.warning_filter(record: logging.LogRecord) bool [source]#
Logging filter to exclude WARNING level messages.
- Parameters:
record – The logging record to check.
- Returns:
False if the record level is WARNING, True otherwise.
- nemo_automodel.components.loggers.log_utils.module_filter(
- record: logging.LogRecord,
- modules_to_filter: list[str],
Logging filter to exclude messages from specific modules.
- Parameters:
record – The logging record to check.
modules_to_filter – A list of module name prefixes to filter out.
- Returns:
False if the record’s logger name starts with any of the specified module prefixes, True otherwise.
- nemo_automodel.components.loggers.log_utils.add_filter_to_all_loggers(
- filter: Union[logging.Filter, Callable[[logging.LogRecord], bool]],
Add a filter to the root logger and all existing loggers.
- Parameters:
filter – A logging filter instance or callable to add.
- nemo_automodel.components.loggers.log_utils._ensure_root_handler_with_formatter(
- formatter: logging.Formatter,
Ensure the root logger has at least one StreamHandler with the given formatter.
If handlers already exist on the root logger, set their formatter to the provided formatter. Otherwise, create a StreamHandler, attach the formatter and RankFilter, and add it to the root logger.
- nemo_automodel.components.loggers.log_utils.setup_logging(
- logging_level: int = logging.INFO,
- filter_warning: bool = True,
- modules_to_filter: Optional[list[str]] = None,
- set_level_for_all_loggers: bool = False,
Set up logging level and filters for the application.
Configures the logging level based on arguments, environment variables, or defaults. Optionally adds filters to suppress warnings or messages from specific modules.
Logging Level Precedence:
Env var
LOGGING_LEVEL
logging_level
argumentDefault:
logging.INFO
Also configures a colorized formatter that includes the date/time.