xlog
A flexible and structured logging library for Python with support for multiple outputs, formats, and async processing.
Features
- Structured Events - Log with context, tags, metrics, and metadata
- Multiple Formats - JSON, Text, ColorJSON, ColorText
- Multiple Outputs - Console, files, custom sinks
- Async Processing - Non-blocking event handling
- Type Safe - Full protocol support for extensibility
Installation
pip install -e .
Quick Start
from xlog import LogStream, FileGroup
# Simple console logging
stream = LogStream(name="app", level="INFO")
stream.log("Application started")
# Log with context
stream.log(
"User login",
level="INFO",
context={"user_id": "123", "ip": "192.168.1.1"}
)
# Add file output
file_group = FileGroup(path="./logs", name="app", async_=True)
stream.add_group(file_group)
stream.log("This goes to console and file")
file_group.close()
Core Components
Events
Create structured log events:
from xlog import Log, Procs
# Log event
event = Log(
message="Request processed",
level="INFO",
code=200,
context={"user": "alice"},
metrics={"duration_ms": "45"}
)
# Subprocess event
import subprocess
result = subprocess.run(["echo", "hello"], capture_output=True)
proc_event = Procs(proc=result)
Streams
Distribute events to multiple destinations:
from xlog import LogStream, LogGroup, FileGroup
# Create stream with multiple outputs
memory_group = LogGroup(name="memory", store=True)
file_group = FileGroup(path="./logs", name="app")
stream = LogStream(
name="app",
level="INFO",
groups=[memory_group, file_group]
)
Formatters
Choose output format:
from xlog import Json, Text, ColorJson, ColorText, LogStream
# JSON format
stream = LogStream(name="app", format=Json(indent=2))
# Colored text for console
stream = LogStream(name="app", format=ColorText())
Groups (Sinks)
Process and store events:
from xlog import LogGroup, FileGroup
# In-memory storage
group = LogGroup(name="memory", store=True, async_=False)
# File storage with async processing
group = FileGroup(
path="./logs",
name="app",
async_=True,
max_queue=1000
)
Real-World Examples
Web Application Logging
from xlog import LogStream, FileGroup, ColorText
access_log = FileGroup(path="./logs", name="access", async_=True)
error_log = FileGroup(path="./logs", name="error", async_=True)
access_stream = LogStream(
name="access",
level="INFO",
format=ColorText(),
groups=[access_log]
)
access_stream.log(
"GET /api/users 200",
level="INFO",
code=200,
context={"user_id": "123", "ip": "192.168.1.1"},
metrics={"response_time_ms": "45"}
)
Data Pipeline Logging
from xlog import LogStream, FileGroup
pipeline = LogStream(
name="etl-pipeline",
groups=[FileGroup(path="./logs", name="pipeline")]
)
pipeline.log("Extract started", context={"source": "database"})
pipeline.log("Transform completed", metrics={"records": "1000"})
pipeline.log("Load finished", context={"target": "warehouse"})
Microservice Tracing
from xlog import LogStream
import uuid
stream = LogStream(name="order-service", level="INFO")
correlation_id = str(uuid.uuid4())
stream.log(
"Processing order",
context={
"correlation_id": correlation_id,
"order_id": "ORD-123"
}
)
stream.log(
"Calling payment-service",
context={
"correlation_id": correlation_id,
"target_service": "payment-service"
}
)
More Examples
See the examples/ directory for complete working examples:
example_basic_logging.py- Getting startedexample_file_logging.py- File outputexample_formatters.py- All formattersexample_web_application.py- HTTP loggingexample_data_pipeline.py- ETL pipelineexample_microservice.py- Distributed tracingexample_monitoring.py- System monitoring
Documentation
Each module includes comprehensive docstrings:
from xlog import LogStream
help(LogStream)
License
MIT
Metadata
Release files for lib-x17-log 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lib_x17_log-1.0.7.tar.gz | 50.3 kB | Without provenance | Details for lib_x17_log-1.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lib_x17_log-1.0.7-py3-none-any.whl | Python 3 | none | any | Details for lib_x17_log-1.0.7-py3-none-any.whl |
Total release size: 120.5 kB
Release files / lib_x17_log-1.0.7.tar.gz
| Download URL | lib_x17_log-1.0.7.tar.gz |
|---|---|
| Size | 50.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2cac82c4241238fb37059d528db1d075b461ca7aa0771a7c6815032cdf93b413
|
|
BLAKE2b-256 checksum How to use checksums |
165f3a90cab230daf83aeec33182414188f435f9c60e071ad4b2eb82a7ae0956
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / lib_x17_log-1.0.7-py3-none-any.whl
| Download URL | lib_x17_log-1.0.7-py3-none-any.whl |
|---|---|
| Size | 70.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e653c54689f342cb4aa1978f7597e6a487d75ddb108731b8e6929f44f48a04ba
|
|
BLAKE2b-256 checksum How to use checksums |
9e7e89bf20a5e935623bdbf899bf499c057155e867e676c9bc6fc758765caacc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for lib-x17-log 1.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.