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:
FormatterRank Aware Logging Formatter.
This formatter extends the standard
logging.Formatterto 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:
- hyped.common.logging.setup_logging(level: int | str, log_file: None | str = None) None[source]¶
Set up the logging configuration.
- Parameters:
- Note: By default, this function is called before execution, with the values
for
levelandlog_filetaken from the environment variablesLOG_LEVELandLOG_FILE, respectively. If these environment variables are not set, the default logging level is"WARNING", and no log file will be created.