pynenc.util.log¶
Module Contents¶
Classes¶
ANSI color codes for terminal coloring. |
|
Custom formatter that adds colors to log output using ANSI color codes. No external dependencies required. |
|
Logger adapter for tasks. |
|
Logger adapter for runners. |
Functions¶
Creates a logger for the specified app with timestamps and optional colored output. |
API¶
- class pynenc.util.log.Colors[source]¶
ANSI color codes for terminal coloring.
- RESET¶
‘\x1b[0m’
- RED¶
‘\x1b[31m’
- GREEN¶
‘\x1b[32m’
- YELLOW¶
‘\x1b[33m’
- BLUE¶
‘\x1b[34m’
- CYAN¶
‘\x1b[36m’
- RED_BG¶
‘\x1b[41m’
- WHITE¶
‘\x1b[37m’
- class pynenc.util.log.ColoredFormatter(fmt: str | None = None, datefmt: str | None = None, style: typing.Literal[%, {, $] = '%', validate: bool = True)[source]¶
Bases:
logging.FormatterCustom formatter that adds colors to log output using ANSI color codes. No external dependencies required.
Initialization
Initialize the formatter with specified format strings.
Args: fmt: The format string for the message datefmt: The format string for datetime objects style: The style of the fmt string validate: Whether to validate the format string
- LEVEL_COLORS¶
None
- format(record: logging.LogRecord) str[source]¶
- pynenc.util.log.create_logger(app: pynenc.app.Pynenc, use_colors: bool = True) logging.Logger[source]¶
Creates a logger for the specified app with timestamps and optional colored output.
- Parameters:
- 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: Optional[str] = None)[source]¶
Bases:
logging.LoggerAdapterLogger 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”))
- class pynenc.util.log.RunnerLogAdapter(logger: logging.Logger, runner_id: str)[source]¶
Bases:
logging.LoggerAdapterLogger adapter for runners.
This adapter adds runner context to log messages.
- Parameters:
logger (logging.Logger) – The logger instance.
runner_id (str) – The ID of the runner.
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”))