This module defines functions to setup the logging of QCoDeS. Calling start_all_logging() will setup logging according to the default configuration.

class qcodes.logger.logger.LogCapture(logger: logging.Logger = <RootLogger root (WARNING)>, level: Optional[Union[int, str]] = None)[source]

Bases: object

Context manager to grab all log messages, optionally from a specific logger.


>>> with LogCapture() as logs:
>>>     code_that_makes_logs(...)
>>> log_str = logs.value
qcodes.logger.logger.conditionally_start_all_logging() None[source]

Start logging if qcodesrc.json setup for it and in tool environment.

This function will start logging if the session is not being executed by a tool such as pytest and under the following conditions depending on the qcodes configuration of config.logger.start_logging_on_import:

For never:

don’t start logging automatically

For always:

Always start logging when not in test environment

For if_telemetry_set_up:

Start logging if the GUID components and the instrumentation key for telemetry are set up, and not in a test environment.

qcodes.logger.logger.console_level(level: Union[int, str]) Iterator[None][source]

Context manager to temporarily change the level of the qcodes console handler.


>>> with logger.console_level(level=logging.DEBUG):
>>>     root_logger.debug('this is now visible')

level – Level to set the console handler to.

qcodes.logger.logger.filter_out_telemetry_log_records(record: logging.LogRecord) int[source]

here we filter any message that is likely to be thrown from opencensus so it is not shown in the user console

qcodes.logger.logger.flush_telemetry_traces() None[source]

Flush the traces of the telemetry logger. If telemetry is not enabled, this function does nothing.

qcodes.logger.logger.generate_log_file_name() str[source]

Generates the name of the log file based on process id, date, time and PYTHON_LOG_NAME

qcodes.logger.logger.get_console_handler() Optional[logging.Handler][source]

Get handle that prints messages from the root logger to the console. Returns None if start_logger() has not been called.

qcodes.logger.logger.get_file_handler() Optional[logging.Handler][source]

Get a handle that streams messages from the root logger to the qcodes log file. To setup call start_logger(). Returns None if start_logger() has not been called.

qcodes.logger.logger.get_formatter() logging.Formatter[source]

Returns logging.Formatter according to FORMAT_STRING_DICT

qcodes.logger.logger.get_formatter_for_telemetry() logging.Formatter[source]

Returns logging.Formatter with only name, function name and message keywords from FORMAT_STRING_DICT

qcodes.logger.logger.get_level_code(level: Union[str, int]) int[source]

Get a logging level code from either a logging level string or a logging level code. Will return the output of logging.getLevelName() if called with a str. If called with an int it will return the int supplied.

qcodes.logger.logger.get_level_name(level: Union[str, int]) str[source]

Get a logging level name from either a logging level code or logging level name. Will return the output of logging.getLevelName() if called with an int. If called with a str it will return the str supplied.

qcodes.logger.logger.get_log_file_name() str[source]

Get the full path to the log file currently used.

qcodes.logger.logger.handler_level(level: Union[int, str], handler: Union[logging.Handler, Sequence[logging.Handler]]) Iterator[None][source]

Context manager to temporarily change the level of handlers.


>>> with logger.handler_level(level=logging.DEBUG, handler=[h1, h1]):
>>>     root_logger.debug('this is now visible')
  • level – Level to set the handlers to.

  • handler – Handle or sequence of handlers which to change.

qcodes.logger.logger.log_qcodes_versions(logger: logging.Logger) None[source]

Log the version information relevant to QCoDeS. This function logs the currently installed qcodes version, whether QCoDeS is installed in editable mode, the installed versions of QCoDeS’ requirements, and the versions of all installed packages.

qcodes.logger.logger.start_all_logging() None[source]

Starts python log module logging and ipython command history logging.

qcodes.logger.logger.start_command_history_logger(log_dir: Optional[str] = None) None[source]

Start logging of the history of the interactive command shell. Works only with IPython and Jupyter. Call function again to set new path to log file.


log_dir – directory where log shall be stored to. If left out, defaults to ~/.qcodes/logs/command_history.log

qcodes.logger.logger.start_logger() None[source]

Start logging of messages passed through the python logging module. This sets up logging to a time based logging. This means that all logging messages on or above filelogginglevel will be written to pythonlog.log All logging messages on or above consolelogginglevel will be written to stderr. filelogginglevel and consolelogginglevel are defined in the qcodesrc.json file.