A logger that maintains logs of both stdout and stderr when models are run.

class allennlp.common.tee_logger.TeeLogger(filename: str, terminal: typing.TextIO, file_friendly_terminal_output: bool) → None[source]

Bases: object

This class is an attempt to maintain logs of both stdout and stderr for when models are run. To use this class, at the beginning of your script insert these lines:

sys.stdout = TeeLogger("stdout.log", sys.stdout)
sys.stderr = TeeLogger("stdout.log", sys.stderr)
allennlp.common.tee_logger.replace_cr_with_newline(message: str)[source]

TQDM and requests use carriage returns to get the training line to update for each batch without adding more lines to the terminal output. Displaying those in a file won’t work correctly, so we’ll just make sure that each batch shows up on its one line. :param message: the message to permute :return: the message with carriage returns replaced with newlines