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
- Trace Execution: Automatically log function calls, returns, and exceptions
- Flexible Querying: Retrieve logs with custom SQL queries
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)
)
Tracing Functions
Logscope includes a @trace decorator to automatically log function calls, returns, and exceptions:
from logscope.tracing import trace
@trace
def my_function(a, b):
return a + b
my_function(2, 3) # Automatically logs the call, return value, and source code
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
Querying Logs
Use the query function to fetch logs directly from Python:
from logscope import query
logs = query("SELECT * FROM logs WHERE event_type = 'error'", db_path='app.db')
for log in logs:
print(log)
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
event_type TEXT -- Custom event type (e.g., 'error', 'info')
);
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;
Retrieve all logs with a custom event type:
SELECT *
FROM logs
WHERE event_type = 'trace';
License
MIT License - See LICENSE file for details
Metadata
Release files for logscope 0.1.10
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 |
|---|---|---|---|---|
| logscope-0.1.10.tar.gz | 20.9 kB | Without provenance | Details for logscope-0.1.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| logscope-0.1.10-py3-none-any.whl | Python 3 | none | any | Details for logscope-0.1.10-py3-none-any.whl |
Total release size: 45.1 kB
Release files / logscope-0.1.10.tar.gz
| Download URL | logscope-0.1.10.tar.gz |
|---|---|
| Size | 20.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4be4aeed2186cbe6e477b8ff63ffe3487e829131b3ef13f34a9f4a47a15fd0b1
|
|
BLAKE2b-256 checksum How to use checksums |
c4ca663466c10978c954dab09d0ac13503e3c4fd0a531fb04fe4f26f4a0d366d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.1
|
Release files / logscope-0.1.10-py3-none-any.whl
| Download URL | logscope-0.1.10-py3-none-any.whl |
|---|---|
| Size | 24.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db0478f81b33d07a484e30892a5d5a30056cfddd195993e42e897f4fbc53fdaa
|
|
BLAKE2b-256 checksum How to use checksums |
100c5631e5271bf0b17e4885b1b7207dcb8070a91aef60ff9cf8d584a10bde77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.1
|
Security for logscope 0.1.10
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.