loguru fast wrapping supports fastapi
Project description
FastLOG
FastLOG is a lightweight wrapper around Loguru with sensible defaults, automatic trace_id, stdlib logging interception, and a directory watcher that can forward log bursts to HTTP, Telegram, or OTLP.
Features
- Zero-config logging:
from fastlog import log; log.info("hello") - Automatic
trace_idinjection for application logs - Simple file logging with rotation and retention via
configure() - Standard
loggingrecords are routed through FastLOG fastlogCLI tails*.logfiles and forwards high-severity events
Installation
uv add fastlog-io
uv add "fastlog-io[otlp]"
Or with pip:
pip install fastlog-io
pip install "fastlog-io[otlp]"
Requirements:
- Python 3.12+
- loguru
Quickstart
from fastlog import configure, log
configure(
level="INFO",
log_path="./logs/app.log",
rotation="10 MB",
retention="7 days",
)
log.info("service started")
with log.trace_ctx():
log.bind(action="api.call").info("request done")
# or use
import logging
logger = logging.getLogger("my-app")
logger.warning("cache miss")
Example output:
2025-10-13 12:23:00.193 | INFO | 3hAhb3OFpU7zXKWBwp | ts.<module>:13 | service started
2025-10-13 12:23:00.194 | WARNING | 1F1FwLwm4Orok0gs0a | [my-app]ts.<module>:16 | cache miss
2025-10-13 12:23:00.194 | INFO | WG8yiDxzO3MCmWy8CB | api.call | request done
Watcher CLI
The fastlog CLI watches a directory of *.log files, resumes from stored byte offsets, batches matching lines, and sends them to one or more destinations.
uv tool install fastlog-io
# HTTP
uv run fastlog ./logs --endpoint "$FASTLOG_NOTIFY_ENDPOINT"
# Telegram
uv run fastlog ./logs \
--tg-token "$FASTLOG_NOTIFY_TG_TOKEN" \
--tg-chat-id "$FASTLOG_NOTIFY_TG_CHAT_ID"
# OTLP
uv run fastlog ./logs --otlp-endpoint "http://127.0.0.1:4318/v1/logs"
Key points:
--min-leveldefaults toWARNING- offsets are stored in
.multilogwatch.state.json - HTTP and Telegram retries default to
3 flush()drains queued batches;close()drains and stops workers- OTLP uses the native OpenTelemetry exporter configuration model when possible
Run uv run fastlog --help for the full option list.
OTLP Notes
Install fastlog-io[otlp] to enable OTLP export.
--otlp-endpointexplicitly overrides the collector endpoint- when
--otlp-endpointis unset, FastLOG falls back toOTEL_EXPORTER_OTLP_LOGS_ENDPOINT, thenOTEL_EXPORTER_OTLP_ENDPOINT --otlp-protocol,OTEL_EXPORTER_OTLP_LOGS_PROTOCOL, orOTEL_EXPORTER_OTLP_PROTOCOLselectshttp,grpc, orhttp/protobuf- headers, timeout, TLS, and resource attributes are delegated to the native OpenTelemetry SDK/exporter env handling
Common OTLP env vars:
| Variable | Description |
|---|---|
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT |
Logs-specific OTLP endpoint |
OTEL_EXPORTER_OTLP_ENDPOINT |
Generic OTLP endpoint fallback |
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL |
http, grpc, or http/protobuf |
OTEL_EXPORTER_OTLP_PROTOCOL |
Generic protocol fallback |
OTEL_EXPORTER_OTLP_LOGS_HEADERS |
Logs-specific request headers |
OTEL_EXPORTER_OTLP_LOGS_TIMEOUT |
Logs-specific exporter timeout |
OTEL_SERVICE_NAME |
Fallback source for resource service.namespace |
OTEL_RESOURCE_ATTRIBUTES |
Extra resource attributes |
RUN_ENV / ENV |
Resource deployment.environment when set |
VERSION |
Resource service.version when set |
Common Environment Variables
| Variable | Default | Description |
|---|---|---|
LOG_PATH |
empty | File output path |
LOG_LEVEL |
INFO |
Default log level |
LOG_ROTATION |
100 MB |
Loguru rotation policy |
FASTLOG_NOTIFY_ENDPOINT |
empty | HTTP destination for watcher notifications |
FASTLOG_NOTIFY_LEVEL |
WARNING |
Default watcher threshold |
FASTLOG_NOTIFY_TIMEOUT |
empty | HTTP timeout override in seconds |
FASTLOG_HTTP_ATTEMPTS |
empty | HTTP and Telegram retry count, default 3 |
FASTLOG_WINDOW_SECONDS |
30 |
Batch window in seconds |
FASTLOG_NOTIFY_MAX_BYTES |
4096 |
Max payload size per request |
FASTLOG_NOTIFY_TG_TOKEN |
empty | Telegram bot token |
FASTLOG_NOTIFY_TG_CHAT_ID |
empty | Telegram chat id |
FASTLOG_OTLP_MAX_BATCH |
256 |
Max records per OTLP export |
Development
uv run --with '.[test]' pytest -q
uv build
uv run --with dist/*.whl --with pytest pytest -q
License
MIT © 2025 OWQ
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastlog_io-0.3.4.tar.gz.
File metadata
- Download URL: fastlog_io-0.3.4.tar.gz
- Upload date:
- Size: 60.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
400f7b1bbbd5f8adeebbe9f5958148f8fea4b7f50852a0a0400551f1c472e614
|
|
| MD5 |
eaa3df4ffcfa432f7848314c61823252
|
|
| BLAKE2b-256 |
e5cb956bd4a06b647d1dfcb358be9fc160201ed0a86711d04423d528c70e3826
|
File details
Details for the file fastlog_io-0.3.4-py3-none-any.whl.
File metadata
- Download URL: fastlog_io-0.3.4-py3-none-any.whl
- Upload date:
- Size: 26.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb14c1df7d86fd19ad555cb2055deabde4ff0edc22ea1264e34d527182491004
|
|
| MD5 |
c935844ac55608106adf4d904abb3ad8
|
|
| BLAKE2b-256 |
c5b155841ab58976994eb1db1af39186b7c0167421b6fca5ccc85bea953ce9a4
|