Handlers¶
This module provides output handlers for ctxlog.
- class ctxlog.handlers.FileRotation(size=None, time=None, keep=5, compression=None)[source]¶
Bases:
objectConfiguration for log file rotation.
- Parameters:
- __init__(size=None, time=None, keep=5, compression=None)[source]¶
Initialize a FileRotation configuration.
- Parameters:
size (
Optional[str]) – Size threshold for rotation (e.g., “20MB”). Mutually exclusive with time.time (
Optional[str]) – Time of day for rotation (e.g., “00.00”). Mutually exclusive with size.keep (
int) – Number of rotated files to keep.compression (
Optional[Literal['gzip','zip']]) – Compression method for old files (e.g., “gzip”, “zip”).
- Raises:
ValueError – If both size and time are specified.
- Return type:
None
- class ctxlog.handlers.Handler(level=None, serialize=False)[source]¶
Bases:
ABCBase class for log handlers.
- class ctxlog.handlers.ConsoleHandler(level=None, serialize=False, color=True, use_stderr=False)[source]¶
Bases:
HandlerHandler that outputs logs to the console.
- class ctxlog.handlers.FileHandler(file_path, level=None, serialize=True, rotation=None)[source]¶
Bases:
HandlerHandler that outputs logs to a file.
- Parameters:
file_path (str)
level (LogLevel | None)
serialize (bool)
rotation (FileRotation | None)
Handler Base Class¶
Console Handler¶
File Handler¶
- class ctxlog.handlers.FileHandler(file_path, level=None, serialize=True, rotation=None)[source]¶
Bases:
HandlerHandler that outputs logs to a file.
- Parameters:
file_path (str)
level (LogLevel | None)
serialize (bool)
rotation (FileRotation | None)
File Rotation¶
- class ctxlog.handlers.FileRotation(size=None, time=None, keep=5, compression=None)[source]¶
Bases:
objectConfiguration for log file rotation.
- Parameters:
- __init__(size=None, time=None, keep=5, compression=None)[source]¶
Initialize a FileRotation configuration.
- Parameters:
size (
Optional[str]) – Size threshold for rotation (e.g., “20MB”). Mutually exclusive with time.time (
Optional[str]) – Time of day for rotation (e.g., “00.00”). Mutually exclusive with size.keep (
int) – Number of rotated files to keep.compression (
Optional[Literal['gzip','zip']]) – Compression method for old files (e.g., “gzip”, “zip”).
- Raises:
ValueError – If both size and time are specified.
- Return type:
None