noether.core.utils.logging.base

Classes

MessageCounter

A logging handler that counts the number of messages logged at each level starting from WARNING.

Functions

log_from_all_ranks()

ContextManager that changes the log level to Info for all ranks and resets it to CRITICAL for non-rank0 ranks.

add_global_handlers([log_file_uri, debug])

Set up logging.getLogger() to log to stdout and optionally to a file.

Module Contents

noether.core.utils.logging.base.log_from_all_ranks()

ContextManager that changes the log level to Info for all ranks and resets it to CRITICAL for non-rank0 ranks.

Return type:

collections.abc.Generator[None, None, None]

class noether.core.utils.logging.base.MessageCounter

Bases: logging.Handler

A logging handler that counts the number of messages logged at each level starting from WARNING.

Initializes the instance - basically setting the formatter to None and the filter list to empty.

min_level = 30
counts: dict[int, int]
emit(record)

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

Parameters:

record (logging.LogRecord)

Return type:

None

log()
Return type:

None

noether.core.utils.logging.base.add_global_handlers(log_file_uri=None, debug=False)

Set up logging.getLogger() to log to stdout and optionally to a file.

Sets up logging for distributed runs: only rank0 logs to console and file, other ranks log only CRITICAL messages to suppress output. This also adds a MessageCounter handler to count the number of messages logged at each level.

Parameters:
  • log_file_uri (pathlib.Path | None) – The path to the log file. If None, no file logging is done.

  • debug (bool) – Whether to log debug messages to stdout.

Returns:

The MessageCounter handler.

Return type:

MessageCounter