ContextLogger#

class wattson.util.context_logger.ContextLogger(host_name: str, logger_name: str, within_xterm: bool, _format: str, lvl: int = 20, active_contexts: Iterable[str] | None = None, logger: Logger | None = None)#

Bases: Logger

Wraps the regular logger, called after as ContextLogger(logging.getLogger(xyz))

Methods

__init__

Initialize the logger with a name and an optional level.

add_contexts

critical

Log 'msg % args' with severity 'CRITICAL'.

debug

Log 'msg % args' with severity 'DEBUG'.

error

Log 'msg % args' with severity 'ERROR'.

exception

Convenience method for logging an ERROR with exception information.

getChild

Get a logger which is a descendant to this one.

info

Log 'msg % args' with severity 'INFO'.

setLevel

Set the logging level of this logger.

warning

Log 'msg % args' with severity 'WARNING'.

Attributes

level

propagate

__init__(host_name: str, logger_name: str, within_xterm: bool, _format: str, lvl: int = 20, active_contexts: Iterable[str] | None = None, logger: Logger | None = None)#

Initialize the logger with a name and an optional level.

critical(msg: Any, *args: Any, exc_info: Any = False, stack_info: bool = False, stacklevel: int = Ellipsis, extra: Dict[str, Any] | None = Ellipsis, **kwargs: Any) None#

Log ‘msg % args’ with severity ‘CRITICAL’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.critical(“Houston, we have a %s”, “major disaster”, exc_info=True)

debug(msg: Any, *args: Any, exc_info: Any = False, stack_info: bool = False, stacklevel: int = Ellipsis, extra: Dict[str, Any] | None = Ellipsis, **kwargs: Any) None#

Log ‘msg % args’ with severity ‘DEBUG’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.debug(“Houston, we have a %s”, “thorny problem”, exc_info=True)

error(msg: Any, *args: Any, exc_info: Any = Ellipsis, stack_info: bool = Ellipsis, stacklevel: int = Ellipsis, extra: Dict[str, Any] | None = Ellipsis, **kwargs: Any) None#

Log ‘msg % args’ with severity ‘ERROR’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.error(“Houston, we have a %s”, “major problem”, exc_info=True)

exception(msg: Any, *args: Any, exc_info: Any = Ellipsis, stack_info: bool = Ellipsis, stacklevel: int = Ellipsis, extra: Dict[str, Any] | None = Ellipsis, **kwargs: Any) None#

Convenience method for logging an ERROR with exception information.

getChild(suffix: str, additional_contexts: Iterable[str] | None = None) ContextLogger#

Get a logger which is a descendant to this one.

This is a convenience method, such that

logging.getLogger(‘abc’).getChild(‘def.ghi’)

is the same as

logging.getLogger(‘abc.def.ghi’)

It’s useful, for example, when the parent logger is named using __name__ rather than a literal string.

info(msg: Any, *args: Any, exc_info: Any = Ellipsis, stack_info: bool = Ellipsis, stacklevel: int = Ellipsis, extra: Dict[str, Any] | None = Ellipsis, **kwargs: Any) None#

Log ‘msg % args’ with severity ‘INFO’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.info(“Houston, we have a %s”, “notable problem”, exc_info=True)

setLevel(level: int) None#

Set the logging level of this logger. level must be an int or a str.

warning(msg: Any, *args: Any, exc_info: Any = Ellipsis, stack_info: bool = Ellipsis, stacklevel: int = Ellipsis, extra: Dict[str, Any] | None = Ellipsis, **kwargs: Any) None#

Log ‘msg % args’ with severity ‘WARNING’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.warning(“Houston, we have a %s”, “bit of a problem”, exc_info=True)