id_translation.logging#

Logging utilities; see Logging for help.

Module Attributes

ENABLE_VERBOSE_LOGGING

Set to enable additional DEBUG-level messages.

LOGGER

Namespace root logger.

EMIT_LOGGED_WARNINGS

Set to False to disable warnings that are emitted as logs.

Functions

enable_verbose_debug_messages([level, ...])

Enable verbose logging.

generate_task_id([seed])

Generate a new task ID.

get_event_key(method, stage)

Construct event_key value.

EMIT_LOGGED_WARNINGS = True#

Set to False to disable warnings that are emitted as logs.

Log messages whose level is set in configuration are often repeated as as specific warning type. For example, setting on_unmapped='warn' will emit both a UnmappedValuesWarning and a logger message. When EMIT_LOGGED_WARNINGS=False, the UnmappedValuesWarning is suppressed.

ENABLE_VERBOSE_LOGGING = False#

Set to enable additional DEBUG-level messages.

The default (False) is controlled by the ID_TRANSLATION_VERBOSE variable. Use enable_verbose_debug_messages() to enable temporarily.

LOGGER = <Logger id_translation (WARNING)>#

Namespace root logger.

Level is set to logging.WARNING=30 by default (or DEBUG if ENABLE_VERBOSE_LOGGING is set). See Logging for details.

enable_verbose_debug_messages(level='verbose', *, use_custom_handler='auto', style='pretty')[source]#

Enable verbose logging. May be used as a context.

Styles

  • minimal: Nothing but the logged message itself.

  • basic: Adds logger name and level.

  • pretty: Adds basic color and task ID (e.g. 🍏 0x2b92). Mark stage (enter=🚀, exit=✅). Sample output: info, debug, verbose.

  • rainbow: Full-color syntax highlighting for strings and keywords. Indent based on stage if level="verbose". Sample output: debug, verbose.

Parameters:
  • level – Log level. If ‘verbose’ (default), set ENABLE_VERBOSE_LOGGING to True.

  • use_custom_handler – Set to False to use existing handlers. If ‘auto’ (default), use existing handlers if one is found (see logging.Logger.hasHandlers()). If True, propagation is disabled for the namespace root logger.

  • style – Formatting style to use. Ignored when use_custom_handler evaluates to False.

Examples

Basic usage.

>>> from id_translation.mapping import Mapper
>>> with enable_verbose_debug_messages():
...     # Context manager; changes are temporary.
...     Mapper().apply("ab", candidates="abc")

Forcing custom handlers. These add formatting (e.g. color) to namespace logger messages.

>>> enable_verbose_debug_messages(use_custom_handler=True, style="rainbow")
>>> Mapper().apply("ab", candidates="abc")

The changes aren’t automatically undone if a regular function call is used.

Notes

Custom handlers emit to standard out.

generate_task_id(seed=None)[source]#

Generate a new task ID.

get_event_key(method, stage)[source]#

Construct event_key value.