ButlerMDC

class lsst.daf.butler.logging.ButlerMDC

Bases: object

Handle setting and unsetting of global MDC records.

The Mapped Diagnostic Context (MDC) can be used to set context for log messages.

Currently there is one global MDC dict. Per-thread MDC is not yet supported.

Methods Summary

MDC(key, value)

Set MDC for this key to the supplied value.

MDCRemove(key)

Clear the MDC value associated with this key.

add_mdc_log_record_factory()

Add a log record factory that adds a MDC record to LogRecord.

clear_mdc()

Clear all MDC entries.

restore_log_record_factory()

Restores the log record factory to the original form.

set_mdc(mdc)

Set the MDC key for this context.

Methods Documentation

classmethod MDC(key: str, value: str) str

Set MDC for this key to the supplied value.

Parameters:
keystr

Key to modify.

valuestr

New value to use.

Returns:
oldstr

The previous value for this key.

classmethod MDCRemove(key: str) None

Clear the MDC value associated with this key.

Can be called even if the key is not known to MDC.

Parameters:
keystr

Key for which the MDC value should be removed.

classmethod add_mdc_log_record_factory() None

Add a log record factory that adds a MDC record to LogRecord.

classmethod clear_mdc() None

Clear all MDC entries.

classmethod restore_log_record_factory() None

Restores the log record factory to the original form.

Does nothing if there has not been a call to add_mdc_log_record_factory.

classmethod set_mdc(mdc: dict[str, str]) Generator[None, None, None]

Set the MDC key for this context.

Parameters:
mdcdict of str, str

MDC keys to update temporarily.

Notes

Other MDC keys are not modified. The previous values are restored on exit (removing them if the were unset previously).