returnn.log
¶
Provides the main class for logging, Log
, and some helpers.
- class returnn.log.Stream(log, lvl)[source]¶
Simple stream wrapper, which provides
write()
andflush()
.
- class returnn.log.Log[source]¶
The main logging class.
- initialize(logs=None, verbosity=None, formatter=None, propagate=False)[source]¶
This resets and configures the “returnn” logger.
- Parameters:
logs (list[str|logging.Handler]) – “stdout”, “|<pipe-cmd>", "<filename>"|”<filename>$date<ext>”. “stdout” is always added when propagate=False.
verbosity (list[int]) – levels 0-5 for the log handlers
formatter (list[str]) – ‘default’, ‘timed’, ‘raw’ or ‘verbose’, for the log handlers
propagate (bool)
- init_by_config(config)[source]¶
- Parameters:
config (returnn.config.Config)
- print_warning(text, prefix_text='WARNING:', extra_text=None)[source]¶
Write a warning to log.v2. Does not write repeated warnings.
- Parameters:
text (str)
prefix_text (str)
extra_text (str|None)
- class returnn.log.StdoutHandler(stream=None)[source]¶
This class is like a StreamHandler using sys.stdout, but always uses whatever sys.stdout is currently set to rather than the value of sys.stdout at handler construction time.
Copied and adopted from logging._StderrHandler.
Initialize the handler.
If stream is not specified, sys.stderr is used.
- class returnn.log.StreamThreadLocal[source]¶
This will just buffer everything, thread-locally, and not forward it to any stream. The idea is that multiple tasks will run in multiple threads and you want to catch all the logging/stdout of each to not clutter the output, and also you want to keep it separate for each.
- returnn.log.wrap_log_streams(alternative_stream, also_sys_stdout=False, tf_log_verbosity=None)[source]¶
- Parameters:
alternative_stream (StreamThreadLocal|StreamDummy)
also_sys_stdout (bool) – wrap sys.stdout as well
tf_log_verbosity (int|str|None) – e.g. “WARNING”
- Returns:
context manager which yields (original info stream v1, alternative_stream)