• full name:

  • parent module:

  • type: function, output_filename=None, *, filename=None, to_stdout='INFO', to_file='INFO', format='%(levelname)-8s: %(message)s', datefmt=None, logger_levels={}, dict_config=None, capture_warnings=None, skip_setup=None)[source]

Configure the logging module.

The default logging setup is given by the following equivalent dict_config (here in [yaml] format for better readability).

version: 1  # mandatory for logging config
disable_existing_loggers: False  # keep module-based loggers already defined!
        format: "%(levelname)-8s: %(message)s"   # options['format']
        class: logging.StreamHandler
        level: INFO         # options['to_stdout']
        formatter: custom
        stream: ext://sys.stdout
        class: logging.FileHandler
        level: INFO         # options['to_file']
        formatter: custom
        filename: output_filename.log   # options['filename']
        mode: a
    handlers: [to_stdout, to_file]
    level: DEBUG


We remove any previously configured logging handlers. This is to handle the case when this function is called multiple times, e.g., because you run multiple Simulation classes sequentially (e.g., run_seq_simulations()).

Deprecated since version 0.9.0: The arguments were previously collected in a dicitonary options. Now they should be given directly as keyword arguments.

  • **kwargs – Keyword arguments as described in the options below.

  • output_filename (None | str) – The filename for where results are saved. The log.filename for the log-file defaults to this, but replacing the extension with .log.


config log
option summary


Whether to call :func:`logging.captureWarnings` to include the warnings int [...]


Formatting string for the `asctime` key in the `format`, e.g. ``"%Y-%m-%d % [...]


Alternatively, a full configuration dictionary for :func:`logging.config.di [...]


Filename for the logfile. [...]


Formatting string, `fmt` argument of :class:`logging.Formatter`. [...]


Set levels for certain loggers, e.g. ``{'': 'WARNING'}`` [...]


If True, don't change anything in the logging setup; just return. [...]


If not None, save log with (at least) the given level to a file. [...]


If not None, print log with (at least) the given level to stdout.

option skip_setup: bool

If True, don’t change anything in the logging setup; just return. This is usefull for testing purposes, where pytest handles the logging setup. All other options are ignored in this case.

option to_stdout: None | "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL"

If not None, print log with (at least) the given level to stdout.

option to_file: None | "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL"

If not None, save log with (at least) the given level to a file. The filename is given by filename.

option filename: str

Filename for the logfile. It defaults to output_filename with the extension replaced to “.log”. If None, no log-file will be created, even with to_file set.

option logger_levels: dict(str, str)

Set levels for certain loggers, e.g. {'': 'WARNING'} to suppress the parameter readouts logs. The keys of this dictionary are logger names, which follow the module structure in tenpy. For example, setting the level for tenpy.simulations will change the level for all loggers in any of those submodules, including the one provided as Simluation.logger class attribute. Hence, all messages from Simulation class methods calling will be affected by that.

option format: str

Formatting string, fmt argument of logging.Formatter. You can for example use "{loglevel:.4s} {asctime} {message}" to include the time stamp of each message into the log - this is usefull to get an idea where code hangs. Find allowed keys here. The style of the formatter is chosen depending on whether the format string contains '%' '{' '$', respectively.

option datefmt: str

Formatting string for the asctime key in the format, e.g. "%Y-%m-%d %H:%M:%S", see logging.Formatter.formatTime().

option dict_config: dict

Alternatively, a full configuration dictionary for logging.config.dictConfig(). If used, all other options except skip_setup and capture_warnings are ignored.

option capture_warnings: bool

Whether to call logging.captureWarnings() to include the warnings into the log.