eformer.loggings#

class eformer.loggings.ColorFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]#

Bases: Formatter

Custom logging formatter that adds color to log output.

Formats log messages with ANSI color codes based on log level and adds timestamps. Each log level has a distinct color for easy identification.

Color mapping:
  • DEBUG: Orange

  • INFO: Blue-Purple

  • WARNING: Yellow

  • ERROR: Red

  • CRITICAL/FATAL: Bold Red

Example output:

(12:34:56 mylogger) This is an info message

Note

Colors are applied via ANSI escape codes and may not display correctly in non-terminal environments or terminals without color support.

format(record: LogRecord) str[source]#

Format a log record with colors and timestamp.

Parameters

record – The log record to format.

Returns

Formatted log string with ANSI color codes.

class eformer.loggings.LazyLogger(name: str, level: int | None = None)[source]#

Bases: object

A lazy-initialized logger with colored output and once-only logging support.

This logger delays initialization until first use, which is useful for: - Avoiding JAX initialization issues in distributed settings - Reducing overhead when logging is not needed - Automatically setting appropriate log levels based on process rank

The logger supports standard log methods (debug, info, warning, error) plus “_once” variants that only log a message once per unique message content.

name#

Logger name for identification in output.

level#

Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL).

Example

>>> logger = LazyLogger("my_module")
>>> logger.info("Starting process...")
>>> logger.warn_once("This warning only appears once")
>>> logger.warn_once("This warning only appears once")  # No output

Note

On non-primary JAX processes (process_index > 0), the log level is automatically set to WARNING to reduce noise in distributed training.

clear_once_cache() None[source]#

Clear the cache of messages logged with *_once methods.

debug_once(message: str, *args: Any, **kwargs: Any) None[source]#

Log a debug message only once per unique message.

error_once(message: str, *args: Any, **kwargs: Any) None[source]#

Log an error message only once per unique message.

info_once(message: str, *args: Any, **kwargs: Any) None[source]#

Log an info message only once per unique message.

property level#
property name#
warn_once(message: str, *args: Any, **kwargs: Any) None[source]#

Log a warning message only once per unique message.

warning_once(message: str, *args: Any, **kwargs: Any) None[source]#

Log a warning message only once per unique message (alias for warn_once).

class eformer.loggings.ProgressLogger(name: str = 'Progress', logger_instance: eformer.loggings.LazyLogger | None = None)[source]#

Bases: object

A progress logger that displays updating progress bars and messages.

This class provides a clean way to show progress for long-running operations with support for progress bars, ETAs, and streaming updates that overwrite the same line in the terminal.

name#

Logger name to use for fallback logging

use_tty#

Whether to use TTY features (auto-detected)

start_time#

Start time of the progress operation

_logger#

Underlying logger for fallback

Example

>>> progress = ProgressLogger("Training")
>>> for i in range(100):
...     progress.update(i, 100, f"Processing batch {i}")
...
>>> progress.complete("Training finished!")
complete(message: str | None = None, show_time: bool = True) None[source]#

Complete the progress and show final message.

Parameters
  • message – Optional completion message

  • show_time – Whether to show total elapsed time

update(current: int, total: int, message: str = '', bar_width: int = 20, show_eta: bool = True, extra_info: str = '') None[source]#

Update the progress display.

Parameters
  • current – Current progress value (0-based)

  • total – Total number of items

  • message – Message to display after the progress bar

  • bar_width – Width of the progress bar in characters

  • show_eta – Whether to show estimated time remaining

  • extra_info – Additional info to append at the end

update_simple(message: str) None[source]#

Update with a simple message without progress bar.

Parameters

message – Message to display

eformer.loggings.create_step_profiler(profile_path: str, start_step: int, duration_steps: int, enable_perfetto: bool) Callable[[int], None][source]#

Creates a step-aware profiler that activates during a specific training window.

Parameters
  • profile_path – Directory to store profiling results

  • start_step – Step number to begin profiling (inclusive)

  • duration_steps – How many steps to profile

  • enable_perfetto – Whether to generate Perfetto UI links

Returns

A callback function for training step profiling

eformer.loggings.extinguish_profiler(enable_perfetto: bool) None[source]#

Safely stops the profiler and handles Perfetto link generation.

Parameters

enable_perfetto – Whether Perfetto links were enabled

eformer.loggings.get_logger(name: str, level: int | None = None) LazyLogger[source]#

Function to create a lazy logger that only initializes when first used.

Parameters
  • name (str) – The name of the logger.

  • level (Optional[int]) – The logging level. Defaults to environment variable LOGGING_LEVEL_ED or “INFO”.

Returns

A lazy logger instance that initializes on first use.

Return type

LazyLogger

eformer.loggings.ignite_profiler(profile_path: str, enable_perfetto: bool = False) None[source]#

Ignites the JAX profiler with optional Perfetto integration.

Parameters
  • profile_path – Directory to store profiling results

  • enable_perfetto – Whether to generate Perfetto UI links (only on primary process)