hyped.common.logging module

This module provides a utility function to configure logging for the application.

The logging setup supports both console and file logging, with a customizable formatter that integrates worker rank information for distributed environments.

class hyped.common.logging.RankAwareFormatter(fmt: str = '\x1b[90m[%(asctime)s] [%(name)s]\x1b[0m %(level_color)s[%(levelname)s]%(reset_color)s %(message)s', **kwargs: Any)[source]

Bases: Formatter

Rank Aware Logging Formatter.

This formatter extends the standard logging.Formatter to include information about the process rank and world size when running in a distributed environment. If the worker information is available, the log message will be formatted to include the rank and world size, along with a color specific to the rank. If the worker information is not available, it falls back to the standard formatting.

format(record: LogRecord) str[source]

Formats the log record.

If worker information is available (e.g., in a distributed environment), the formatted log message will include the process rank and world size, along with a color specific to the rank. If the worker information is not available, it falls back to the standard formatting.

Parameters:

record (logging.LogRecord) – The log record to format.

Returns:

The formatted log message.

Return type:

str

hyped.common.logging.setup_logging(level: int | str, log_file: None | str = None) None[source]

Set up the logging configuration.

Parameters:
  • level (None | int | str, optional) – The logging level.

  • log_file (None | str, optional) – The file path for logging output. If set to None (default) no log file is created.

Note: By default, this function is called before execution, with the values

for level and log_file taken from the environment variables LOG_LEVEL and LOG_FILE, respectively. If these environment variables are not set, the default logging level is "WARNING", and no log file will be created.