logging
Logging configuration for snakesee.
This module provides centralized logging configuration with support for both human-readable and structured (JSON) output formats.
Usage
from snakesee.logging import configure_logging
Basic configuration¶
configure_logging(level="INFO")
JSON output for log aggregation¶
configure_logging(level="DEBUG", json_output=True)
Classes¶
ColoredFormatter ¶
Bases: Formatter
Colored formatter for human-readable console output.
Source code in snakesee/logging.py
Functions¶
format ¶
Format a log record with optional color.
Source code in snakesee/logging.py
StructuredFormatter ¶
Bases: Formatter
JSON formatter for structured log output.
Produces JSON lines suitable for log aggregation systems like Elasticsearch, Splunk, or CloudWatch.
Each log entry includes: - timestamp: ISO 8601 format with timezone - level: Log level name - logger: Logger name - message: Log message - Additional fields from the record's extra dict
Source code in snakesee/logging.py
Functions¶
format ¶
Format a log record as JSON.
Source code in snakesee/logging.py
Functions¶
configure_logging ¶
configure_logging(level: str | int = 'WARNING', json_output: bool = False, stream: TextIO | None = None, include_timestamp: bool = True) -> None
Configure logging for snakesee.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str | int
|
Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL or int). |
'WARNING'
|
json_output
|
bool
|
If True, output structured JSON logs. |
False
|
stream
|
TextIO | None
|
Output stream. Defaults to stderr. |
None
|
include_timestamp
|
bool
|
Include timestamp in human-readable output. |
True
|
Source code in snakesee/logging.py
get_logger ¶
Get a logger for a snakesee module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Module name (will be prefixed with 'snakesee.'). |
required |
Returns:
| Type | Description |
|---|---|
Logger
|
Logger instance. |
Example
logger = get_logger(name) logger.info("Processing file", extra={"file": path})