class composer.loggers.FileLogger(filename='{run_name}/logs-rank{rank}.txt', remote_file_name=None, *, capture_stdout=True, capture_stderr=True, buffer_size=1, log_traces=True, flush_interval=100, overwrite=False)[source]#

Log data to a file.

Example usage:
from composer.loggers import FileLogger
from composer.trainer import Trainer
file_logger = FileLogger(
trainer = Trainer(

Example output:

[FIT][step=2]: { "logged_metric": "logged_value", }
[EPOCH][step=2]: { "logged_metric": "logged_value", }
[BATCH][step=2]: { "logged_metric": "logged_value", }
[EPOCH][step=3]: { "logged_metric": "logged_value", }
  • filename (str, optional) โ€“

    Format string for the filename.

    The following format variables are available:




    The name of the training run. See Logger.run_name.


    The global rank, as returned by get_global_rank().


    The local rank of the process, as returned by get_local_rank().


    The world size, as returned by get_world_size().


    The local world size, as returned by get_local_world_size().


    The node rank, as returned by get_node_rank().


    When training with multiple devices (i.e. GPUs), ensure that '{rank}' appears in the format. Otherwise, multiple processes may attempt to write to the same file.

    Consider the following example when using default value of โ€˜{run_name}/logs-rank{rank}.txtโ€™:

    >>> file_logger = FileLogger(filename='{run_name}/logs-rank{rank}.txt')
    >>> trainer = Trainer(loggers=[file_logger], run_name='my-awesome-run')
    >>> file_logger.filename

    Default: โ€˜{run_name}/logs-rank{rank}.txtโ€™

  • remote_file_name (str, optional) โ€“

    Format string for the logfileโ€™s name.

    The logfile will be periodically logged (according to the flush_interval) as a file. The file name will be determined by this format string.

    See also

    Uploading Files for notes for file uploading.

    The same format variables for filename are available. Setting this parameter to None (the default) will use the same format string as filename. It is sometimes helpful to deviate from this default. For example, when filename contains an absolute path, it is recommended to set this parameter explicitely, so the absolute path does not appear in any remote file stores.

    Leading slashes ('/') will be stripped.

    Default: None (which uses the same format string as filename)

  • capture_stdout (bool, optional) โ€“ Whether to include the stdout``in ``filename. (default: True)

  • capture_stderr (bool, optional) โ€“ Whether to include the stderr``in ``filename. (default: True)

  • buffer_size (int, optional) โ€“ Buffer size. See open(). Default: 1 for line buffering.

  • log_traces (bool, optional) โ€“ Whether to log algorithm traces. See Engine for more detail.

  • flush_interval (int, optional) โ€“ How frequently to flush the log to the file in batches Default: 100.

  • overwrite (bool, optional) โ€“ Whether to overwrite an existing logfile. (default: False)

property filename#

The filename for the logfile.

property remote_file_name#

The remote file name for the logfile.

write(prefix, s)[source]#

Write to the logfile.


If the write occurs before the Event.INIT event, the write will be enqueued, as the file is not yet open.

  • prefix (str) โ€“ A prefix for each line in the logfile.

  • s (str) โ€“ The string to write. Each line will be prefixed with prefix.