pynenc.util.log#

Module Contents#

Classes#

TaskLoggerAdapter

Logger adapter for tasks.

RunnerLogAdapter

Logger adapter for runners.

Functions#

create_logger

Creates a logger for the specified app.

API#

pynenc.util.log.create_logger(app: pynenc.app.Pynenc) logging.Logger[source]#

Creates a logger for the specified app.

Parameters:

app (Pynenc) – The app instance for which the logger is created.

Returns:

The created logger.

Raises:

ValueError – If the logging level is invalid.

class pynenc.util.log.TaskLoggerAdapter(logger: logging.Logger, task_id: str, invocation_id: str | None = None)[source]#

Bases: logging.LoggerAdapter

Logger adapter for tasks.

This adapter adds task and invocation context to log messages.

Initialization

Initialize the adapter with a logger and a dict-like object which provides contextual information. This constructor signature allows easy stacking of LoggerAdapters, if so desired.

You can effectively pass keyword arguments as shown in the following example:

adapter = LoggerAdapter(someLogger, dict(p1=v1, p2=“v2”))

set_context(task_id: str, invocation_id: str | None) None[source]#

Sets the context for logging.

Parameters:
  • task_id (str) – The ID of the task.

  • invocation_id (Optional[str]) – The ID of the invocation.

process(msg: Any, kwargs: Any) Any[source]#

Processes a log message, adding task and invocation context.

Parameters:
  • msg (Any) – The log message.

  • kwargs (Any) – Additional keyword arguments.

Returns:

The processed message.

class pynenc.util.log.RunnerLogAdapter(logger: logging.Logger, runner_id: str)[source]#

Bases: logging.LoggerAdapter

Logger adapter for runners.

This adapter adds runner context to log messages.

Initialization

Initialize the adapter with a logger and a dict-like object which provides contextual information. This constructor signature allows easy stacking of LoggerAdapters, if so desired.

You can effectively pass keyword arguments as shown in the following example:

adapter = LoggerAdapter(someLogger, dict(p1=v1, p2=“v2”))

process(msg: Any, kwargs: Any) Any[source]#

Processes a log message, adding runner context.

Parameters:
  • msg (Any) – The log message.

  • kwargs (Any) – Additional keyword arguments.

Returns:

The processed message.