Skip to content

log

Logging of the package.

pymetadata follows the convention for libraries: it only gets loggers and logs to them, it does not configure logging. Handlers, levels and formatting are left to the application, which keeps the messages of the package under the control of whoever uses it.

Modules get their logger from the standard library with

import logging

logger = logging.getLogger(__name__)

All loggers are therefore below the pymetadata logger, so an application configures them in one place:

import logging

logging.getLogger("pymetadata").setLevel(logging.WARNING)

For scripts and interactive work the rich formatting of the package can be enabled explicitly, which is what the examples do:

from pymetadata import log

log.enable_rich_logging()

enable_rich_logging

enable_rich_logging(level=INFO, console=None)

Log the messages of the package on a rich console.

This configures logging and is meant for scripts, examples and interactive work. Applications should configure logging themselves instead of calling this. Calling it repeatedly replaces the handler instead of adding a second one.

Parameters:

Name Type Description Default
level int

level from which messages are logged

INFO
console Console | None

console to log on, the console of the package by default

None

Returns:

Type Description
Logger

The pymetadata logger.