Common structured logging utilities.
| Class | |
Structured logging format to use. |
| Function | console |
Formatter rendering structlog and plain stdlib records as Key=Value lines, like LogFormat.KEY_VALUE. |
| Function | json |
Formatter rendering structlog and plain stdlib records as JSON lines, like LogFormat.JSON. |
| Function | setup |
Set up structured logging. |
| Constant | DEFAULT |
Undocumented |
| Function | _console |
Undocumented |
| Function | _elapsed |
Convert elapsed entry in structlog processor event dict to shorter format. |
| Function | _exception |
Render an exception as its last traceback line ExcType: message only, after the log line. |
| Function | _file |
Undocumented |
| Function | _flag |
Undocumented |
| Function | _format |
Format given seconds into short human-readable string. |
| Function | _from |
Return the environment variable name converted; value if it's unset or invalid. |
| Function | _level |
Undocumented |
| Function | _path |
Convert path entry in structlog processor event dict to simple string. |
| Function | _resolve |
AUTOMATIC: KEY_VALUE on a terminal, else JSON. |
| Function | _set |
Undocumented |
| Function | _shared |
Processors for structlog and foreign (plain stdlib) records alike, before rendering. |
| Constant | _LOGGER |
Undocumented |
| Variable | _logging |
Global flag indicated whether logging is initialized. |
Formatter rendering structlog and plain stdlib records as Key=Value lines, like LogFormat.KEY_VALUE.
For handlers of applications with their own logging setup, after setup_logging with LogFormat.KEY_VALUE.
| Parameters | |
colors:bool | ANSI colors in the output; also the local variables in Rich tracebacks. |
tracebacks:bool | Full tracebacks (Rich if installed); otherwise only their last line ExcType: message. |
| Returns | |
logging.Formatter | Undocumented |
Formatter rendering structlog and plain stdlib records as JSON lines, like LogFormat.JSON.
For handlers of applications with their own logging setup, after setup_logging with LogFormat.JSON.
int | str = logging.NOTSET, log_levels: Mapping[ str, int | str] | None = None, log_format: LogFormat = LogFormat.AUTOMATIC, enable_rich_tracebacks: bool = True, force_basic_config: bool = False, console: bool = True, log_file: str | os.PathLike[ str] | None = None, log_file_level: int | str = logging.NOTSET, log_file_max_bytes: int = 0, log_file_backups: int = 0):
¶
Set up structured logging.
Environment variables override the arguments: LOG_FORMAT (key_value, json, automatic), LOG_LEVEL (log_min_level), LOG_CONSOLE (1 / 0), LOG_FILE (empty: none), LOG_FILE_LEVEL, LOG_FILE_MAX_BYTES and LOG_FILE_BACKUPS. Invalid values are logged and ignored.
If the root logger already has handlers (and force_basic_config is false), none are added: those handlers
need console_formatter to render structlog records.
| Parameters | |
logint | str | Minimum logging level for structlog loggers. |
logMapping[ | Logging levels for all loggers. Maps logger name to level. Defaults to DEFAULT_LOG_LEVELS. |
logLogFormat | Logging format for all loggers, on the console and in the log file. |
enablebool | Enable Rich tracebacks if KEY_VALUE log format is used. |
forcebool | force parameter of logging.basicConfig. |
console:bool | Log to stderr. |
logstr | os.PathLike[ | Also log to this file: appended, UTF-8, created on the first record, no colors. |
logint | str | Minimum level of the records written to log_file. |
logint | Rotate log_file at this size; 0: never. |
logint | Number of rotated files kept (.1, .2, ...). |
bool, tracebacks: bool, rich_tracebacks: bool) -> logging.Formatter:
¶
Undocumented
str | os.PathLike[ str], *, level: int | str, max_bytes: int, backups: int) -> logging.Handler:
¶
Undocumented