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() and flush().

write(msg)[source]#
Parameters:

msg (str) –

flush()[source]#

Flush, i.e. writes to the log.

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) –

print_deprecation_warning(text, behavior_version=None)[source]#

Write a deprecation warning to log.v2. Does not write repeated warnings.

Parameters:
  • text (str) –

  • behavior_version (int|None) – if this deprecation is already covered by a behavior_version check

flush()[source]#

Flush all streams.

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.

property stream[source]#
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.

write(msg)[source]#
Parameters:

msg (str) –

flush()[source]#

Ignored.

class returnn.log.StreamDummy[source]#

This will just discard any data.

write(msg)[source]#

Ignored.

Parameters:

msg (str) –

flush()[source]#

Ignored.

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)