Logging Utilities

This module contains utilities for configuring logging.

vivarium.engine.framework.logging.utilities.configure_logging_to_terminal(verbosity, long_format=True)[source]

Configure logging to print to the sys.stdout.

Return type:

None

Parameters:
  • verbosity (int) – The verbosity level of the logging. 0 logs at the WARNING level, 1 logs at the INFO level, and 2 or more logs at the DEBUG level.

  • long_format (bool) – Whether to use the long format for logging messages, which includes explicit information about the simulation context and component in the log messages.

vivarium.engine.framework.logging.utilities.configure_logging_to_file(output_directory)[source]

Configure logging to write to a file in the provided output directory.

Return type:

None

Parameters:

output_directory (Path) – The directory to write the log file to.

vivarium.engine.framework.logging.utilities.add_logging_sink(sink, verbosity, long_format, colorize, serialize)[source]

Add a logging sink to the logger.

Return type:

int

Parameters:
  • sink (Path | TextIO) – The sink to add. Can be a file path, a file object, or a callable.

  • verbosity (int) – The verbosity level. 0 is the default and will only log warnings and errors. 1 will log info messages. 2 or more will log debug messages.

  • long_format (bool) – Whether to use the long format for logging messages. The long format includes the simulation name and component name. The short format only includes the file name and line number.

  • colorize (bool) – Whether to colorize the log messages.

  • serialize (bool) – Whether to serialize log messages. This is useful when logging to a file or a database.

vivarium.engine.framework.logging.utilities.get_log_level(verbosity)[source]

Map a verbosity count to a loguru log level.

The mapping is clamped at both ends: any value of 0 or below logs at the WARNING level, 1 logs at INFO, and 2 or above logs at DEBUG.

Return type:

str

Parameters:

verbosity (int) – The verbosity level, typically a -v count from the command line.

vivarium.engine.framework.logging.utilities.list_loggers()[source]

Utility function for analyzing the logging environment.

Return type:

None