> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/automodel/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/automodel/_mcp/server.

# nemo_automodel.components.loggers.log_utils

## Module Contents

### Classes

| Name                                                                            | Description                                                             |
| ------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [`ColorFormatter`](#nemo_automodel-components-loggers-log_utils-ColorFormatter) | Logging formatter that colorizes the level name and includes date/time. |
| [`RankFilter`](#nemo_automodel-components-loggers-log_utils-RankFilter)         | A logging filter that controls log output based on the process rank.    |

### Functions

| Name                                                                                                                      | Description                                                                     |
| ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| [`_ensure_root_handler_with_formatter`](#nemo_automodel-components-loggers-log_utils-_ensure_root_handler_with_formatter) | Ensure the root logger has at least one StreamHandler with the given formatter. |
| [`add_filter_to_all_loggers`](#nemo_automodel-components-loggers-log_utils-add_filter_to_all_loggers)                     | Add a filter to the root logger and all existing loggers.                       |
| [`module_filter`](#nemo_automodel-components-loggers-log_utils-module_filter)                                             | Logging filter to exclude messages from specific modules.                       |
| [`setup_logging`](#nemo_automodel-components-loggers-log_utils-setup_logging)                                             | Set up logging level and filters for the application.                           |

### Data

[`_COLOR_RESET`](#nemo_automodel-components-loggers-log_utils-_COLOR_RESET)

[`_LEVEL_TO_COLOR`](#nemo_automodel-components-loggers-log_utils-_LEVEL_TO_COLOR)

[`logger`](#nemo_automodel-components-loggers-log_utils-logger)

### API

```python
class nemo_automodel.components.loggers.log_utils.ColorFormatter(
    fmt: str | None = None,
    datefmt: str | None = None,
    use_color: bool = True
)
```

**Bases:** `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.

```python
nemo_automodel.components.loggers.log_utils.ColorFormatter._stream_supports_color() -> bool
```

```python
nemo_automodel.components.loggers.log_utils.ColorFormatter.format(
    record: logging.LogRecord
) -> str
```

```python
class nemo_automodel.components.loggers.log_utils.RankFilter()
```

**Bases:** `Filter`

A logging filter that controls log output based on the process rank.

This filter allows log messages only for rank 0 by default.

```python
nemo_automodel.components.loggers.log_utils.RankFilter.filter(
    record: logging.LogRecord
) -> bool
```

Decide whether to log the provided record.

**Parameters:**

The log record to be evaluated.

**Returns:** `bool`

True if the log record should be logged, False otherwise.

```python
nemo_automodel.components.loggers.log_utils._ensure_root_handler_with_formatter(
    formatter: logging.Formatter
) -> None
```

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.

```python
nemo_automodel.components.loggers.log_utils.add_filter_to_all_loggers(
    filter: typing.Union[logging.Filter, typing.Callable[[LogRecord], bool]]
) -> None
```

Add a filter to the root logger and all existing loggers.

**Parameters:**

A logging filter instance or callable to add.

```python
nemo_automodel.components.loggers.log_utils.module_filter(
    record: logging.LogRecord,
    modules_to_filter: list[str]
) -> bool
```

Logging filter to exclude messages from specific modules.

**Parameters:**

The logging record to check.

A list of module name prefixes to filter out.

**Returns:** `bool`

False if the record's logger name starts with any of the specified

```python
nemo_automodel.components.loggers.log_utils.setup_logging(
    logging_level: int = logging.INFO,
    modules_to_filter: typing.Optional[list[str]] = None,
    set_level_for_all_loggers: bool = False
) -> None
```

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 messages from specific
modules.

Logging Level Precedence:

1. Env var `LOGGING_LEVEL`
2. `logging_level` argument
3. Default: `logging.INFO`

Also configures a colorized formatter that includes the date/time.

```python
nemo_automodel.components.loggers.log_utils._COLOR_RESET = '\x1b[0m'
```

```python
nemo_automodel.components.loggers.log_utils._LEVEL_TO_COLOR = {logging.DEBUG: '\x1b[36m', logging.INFO: '\x1b[32m', logging.WARNING: '\x1b[33m...
```

```python
nemo_automodel.components.loggers.log_utils.logger = logging.getLogger(__name__)
```