Fancy logging with local SQLite storage.
Project description
LogScope
LogScope is a Python logging library that brings together SQLite storage and pretty console output. Write logs to both your terminal and a queryable database with a dead-simple API.
Features
- Write logs to SQLite + console simultaneously
- Smart context tracking (captures function names and calling code)
- Colorized, pretty console output
- Thread-safe SQLite operations
- Dead simple API
Installation
pip install logscope
Quick Start
from logscope import logger
# Get a logger with default settings (SQLite + console output)
log = logger()
# Log some things!
log("Starting analysis")
log("Processing item", {"id": 123, "status": "pending"})
Configuration
import logging
from logscope import logger
# All settings are optional
log = logger(
db_path='app.db', # Where to store the SQLite database
style='plain', # 'plain' or 'colorful' console output
name='MyApp', # Logger name (defaults to timestamp)
level=logging.INFO # Logging level (default: DEBUG)
)
How It Works
Each log message is:
- Written to a SQLite database for later querying
- Displayed in your console with context details
- Tracked with its calling context (which function called it and how)
Example console output:
2024-03-15 14:23:45.123456> Starting analysis
· process_data:data = process_data("large_file.txt")
· /path/to/script.py:45
Database Schema
Logs are stored in SQLite with this schema:
CREATE TABLE logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
run TEXT, -- Unique ID for each logger instance
timestamp TEXT, -- ISO format with microseconds
message TEXT, -- The logged message
filename TEXT, -- Source file path
lineno INTEGER, -- Line number
source TEXT, -- The actual calling code
function TEXT -- Calling function name
);
Example Queries
Get the last 10 logs from a specific run:
SELECT timestamp, message, function
FROM logs
WHERE run = '2024-03-15 14:23:45.123456'
ORDER BY timestamp DESC
LIMIT 10;
Find all errors from a specific function:
SELECT timestamp, message
FROM logs
WHERE function = 'process_data'
AND message LIKE '%error%'
ORDER BY timestamp;
License
MIT License - See LICENSE file for details
Project details
Release history Release notifications | RSS feed
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 logscope-0.1.0.tar.gz.
File metadata
- Download URL: logscope-0.1.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92aae04b9c128c622ee1c036647ae11dad8b431f92723d0a7c71d18bcf449efb
|
|
| MD5 |
bca9ea4a0a361a32d90f2120bc07918e
|
|
| BLAKE2b-256 |
ffc1471df9f380efe940606261900ea7a5d8468b7b9cca06db0b6fa8a1f6e655
|
File details
Details for the file logscope-0.1.0-py3-none-any.whl.
File metadata
- Download URL: logscope-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9225743b66fd22a351c49ee46c972ade40c5ca51b05e1645a52798425ceebccd
|
|
| MD5 |
598634145aa0cab5abab2a98c8ac0076
|
|
| BLAKE2b-256 |
7c51d7893923a188ecff107f16f83b541795a44aaae60767a2edb23d7e97397d
|