gws.core.log

Minimal logging facility that writes to stdout.

Source code: gws.core.log

Module Contents

gws.core.log.critical(msg: str, *args, **kwargs)

Log a message at the critical level.

Parameters:
  • msg – Message, optionally with % placeholders.

  • *args – Values for the placeholders. A single dict is used as a mapping.

  • **kwargs – stacklevel to adjust the reported source location in debug mode.

gws.core.log.debug(msg: str, *args, **kwargs)

Log a message at the debug level.

Parameters:
  • msg – Message, optionally with % placeholders.

  • *args – Values for the placeholders. A single dict is used as a mapping.

  • **kwargs – stacklevel to adjust the reported source location in debug mode.

gws.core.log.error(msg: str, *args, **kwargs)

Log a message at the error level.

Parameters:
  • msg – Message, optionally with % placeholders.

  • *args – Values for the placeholders. A single dict is used as a mapping.

  • **kwargs – stacklevel to adjust the reported source location in debug mode.

gws.core.log.exception(msg: str = '', *args, **kwargs)

Log the exception being handled, with its backtrace, at the error level.

Parameters:
  • msg – Message, optionally with % placeholders. Defaults to the first line of the backtrace.

  • *args – Values for the placeholders. A single dict is used as a mapping.

  • **kwargs – stacklevel to adjust the reported source location in debug mode.

gws.core.log.exception_backtrace(exc: BaseException | None) → list

Return the exception backtrace as a list of strings.

The backtrace includes the chain of causes and contexts.

Parameters:

exc – An exception.

Returns:

A list of lines. The first line is a summary with the exception name, the first message and the location.

gws.core.log.get_level() → str

Return the name of the current log level.

Returns:

A level name like INFO.

gws.core.log.if_debug(fn, *args)

If the log level is debug, apply the function to args and log the result.

Exceptions raised by the function are logged instead of the result.

Parameters:
  • fn – A function that returns a message.

  • *args – Arguments for the function.

gws.core.log.info(msg: str, *args, **kwargs)

Log a message at the info level.

Parameters:
  • msg – Message, optionally with % placeholders.

  • *args – Values for the placeholders. A single dict is used as a mapping.

  • **kwargs – stacklevel to adjust the reported source location in debug mode.

class gws.core.log.Level

Log level constants, as in the standard logging module.

ALL = 0
CRITICAL = 50
DEBUG = 10
ERROR = 40
INFO = 20
NOTSET = 0
WARN = 30
WARNING = 30
gws.core.log.log(level: int, msg: str, *args, **kwargs)

Log a message at the given level.

Parameters:
  • level – Numeric log level.

  • msg – Message, optionally with % placeholders.

  • *args – Values for the placeholders. A single dict is used as a mapping.

  • **kwargs – stacklevel to adjust the reported source location in debug mode.

gws.core.log.set_level(level: int | str | None)

Set the current log level.

Parameters:

level – A numeric level, a level name like DEBUG, or None for INFO.

gws.core.log.warning(msg: str, *args, **kwargs)

Log a message at the warning level.

Parameters:
  • msg – Message, optionally with % placeholders.

  • *args – Values for the placeholders. A single dict is used as a mapping.

  • **kwargs – stacklevel to adjust the reported source location in debug mode.