Libreria Python per logging/stampa formattata con prefissi coerenti, filtro visibilità, log strutturati JSON opzionali e gestione session/remote id.
Project description
Printer Logging
Libreria Python per logging/stampa formattata con prefissi coerenti, filtro di visibilità, log strutturati JSON opzionali e gestione session/remote id.
Caratteristiche
- Prefissi coerenti: custom logs, session id, log_code
- Filtro di visibilità: controllo tramite
DebuggingMode(NORMAL, VERBOSE, DEBUG) - Output flessibile: stdout/stderr o
logging.Loggerintegrato - Log strutturati JSON: opzionali quando
use_structured_logging=True - Gestione log_code: risoluzione automatica con fallback e mapping configurabile
Installazione
pip install printer-logging
Quickstart
Uso diretto (classe Printer)
from printer import Printer, DebuggingMode, set_session_id
set_session_id("abc-123")
p = Printer(
debugging_mode=DebuggingMode.DEBUG,
name="MyApp",
use_structured_logging=False,
)
p.info("Hello") # default: print
p.warning("Bad request", log_code=400)
p.error("Boom", log_code=500)
Uso con API funzionale (singleton)
import printer
from printer import DebuggingMode
printer.configure_printer(
debugging_mode=DebuggingMode.DEBUG,
name="MyApp",
use_structured_logging=True,
default_output_type="log",
)
printer.info("Hello", log_code=200, category="REQUEST_RECEIVED")
printer.warning("Bad request", log_code=400)
printer.error("Error occurred", log_code=500)
DebuggingMode
Controlla la visibilità dei log:
NORMAL: mostra soloWARNING/ERROR/CRITICALVERBOSE: mostraINFO+(escludeDEBUG)PRODUCTION: equivalente aVERBOSEDEBUG: mostra tutto
Log strutturati JSON
Quando use_structured_logging=True e output_type="log", viene emesso anche un JSON per ogni evento con:
timestamp,level,logger,message,log_codecustom_logs_prefix,session_idcontext(state/phase/category) se presentiexceptionquando applicabile
Session ID
Gestito via contextvars, funziona anche in async:
from printer import set_session_id, get_session_id
set_session_id("abc-123")
assert get_session_id() == "abc-123"
Requisiti
- Python >= 3.9
Documentazione completa
Per dettagli completi, esempi avanzati e configurazione, consulta il README completo nel repository.
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 printer_logging-1.0.3.tar.gz.
File metadata
- Download URL: printer_logging-1.0.3.tar.gz
- Upload date:
- Size: 31.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed29d20bd97c9e02668bbc29c453c51b939e5d62f4405d516ce1812c46d6cdc8
|
|
| MD5 |
9dc1a9d0e87ff8b90780537280d5c755
|
|
| BLAKE2b-256 |
1fe2a4ef99fe90c0c1411962a468aedef5412fbee790dbb5807f753fdd13a2fd
|
File details
Details for the file printer_logging-1.0.3-py3-none-any.whl.
File metadata
- Download URL: printer_logging-1.0.3-py3-none-any.whl
- Upload date:
- Size: 29.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95de5862c63def3e52e07303090d8dd20bd4ee6367895de7aaf448ec3bbee624
|
|
| MD5 |
63df6fb7c30ec1cd4ac8946cc8a5ef4f
|
|
| BLAKE2b-256 |
3ebffac8f2c04cf7109a9b9a167c3a335d00f23a75b2ff0f8faf5cc07a44d63d
|