ksuit.utils.logging.core¶
Classes¶
A logging handler that counts the number of messages logged at each level starting from WARNING. |
Functions¶
|
Set up logging.getLogger() to log to stdout and optionally to a file. |
ContextManager that changes the log level to Info for all ranks and resets it to CRITICAL for non-rank0 ranks. |
Module Contents¶
- ksuit.utils.logging.core.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:
- ksuit.utils.logging.core.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 ksuit.utils.logging.core.MessageCounter¶
Bases:
logging.HandlerA 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¶
- 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