Dead-simple logging: what python's logging should've been
Project description
Dead Simple Logging
What python's
logging
should've been
Installation
pip install dslog
Usage
- Any custom "handler" (aka function to actually print)
import rich
from dslog import Logger
logger = Logger.of(rich.print) \
.limit('WARNING') \
.format(lambda *objs, level: (f'[bold][{level}][/]', *objs))
logger('My message', ..., level='INFO')
# doesn't print anything
logger('Oops!', { 'more': 'details' }, level='WARNING')
# [WARNING] Oops! { 'more', 'details' } ([WARNING] in bold text)
- Or some of the predefined ones, which come already formatted
Logger.rich()
Logger.file('log.txt')
- Or the best default logger
Logger.empty()
uvicorn
/fastapi
Logging
If you've used it before, you know it sucks. No more:
from fastapi import FastAPI
import uvicorn
from dslog import Logger
from dslog.uvicorn import setup_loggers_lifespan, DEFAULT_FORMATTER, ACCESS_FORMATTER
logger = Logger.click().prefix('[MY API]')
app = FastAPI(lifespan=setup_loggers_lifespan(
access=logger.prefix('[ACCESS]').format(ACCESS_FORMATTER).limit('WARNING'),
uvicorn=logger.format(DEFAULT_FORMATTER).limit('INFO'),
))
uvicorn.run(app)
# The initial logs will run (uvicorn is quite stubborn):
# INFO: Started server process [95349]
# INFO: Waiting for application startup.
# But then, all the logs are controlled by you (ie. your logger)
# [INFO] [MY API] Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
# [WARNING] [MY API] [ACCESS] ...
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
dslog-0.1.14.tar.gz
(6.9 kB
view details)
Built Distribution
File details
Details for the file dslog-0.1.14.tar.gz
.
File metadata
- Download URL: dslog-0.1.14.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cb011f6fe4b58474e44d14cc61a03be825f409463c4a36a7668eacfa64ac215 |
|
MD5 | b152658306003b0218ff9200faa5b221 |
|
BLAKE2b-256 | 04ae98ae346d6870059329f678f0da57b381d955c062b5f2a8e3fed976b58869 |
Provenance
File details
Details for the file dslog-0.1.14-py3-none-any.whl
.
File metadata
- Download URL: dslog-0.1.14-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 516bee29809b5816c9202ab1088dc018ed2e3a90744bf0114b03d282e2353261 |
|
MD5 | 09d1711f9d50ac2f338f4766fe81920f |
|
BLAKE2b-256 | 289a64261845997ea64cad4f5f96363496b89526fc8943b2348e685908e9c838 |