Dead-simple logging: what python's logging should've been
Project description
Dead Simple Logging
What python's
loggingshould'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.2.9.tar.gz
(7.0 kB
view details)
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
dslog-0.2.9-py3-none-any.whl
(9.5 kB
view details)
File details
Details for the file dslog-0.2.9.tar.gz.
File metadata
- Download URL: dslog-0.2.9.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9552618da4a8ae07bd9805eb0adc523d1e13c2cb9c6ab40d181909ea2b6092fe
|
|
| MD5 |
7981be2733684dd4848b338647bebb22
|
|
| BLAKE2b-256 |
530a0b21e4b86b39c38dfb38ce1e67884e20de871bc1bd3b3a357dc9c3a8305b
|
File details
Details for the file dslog-0.2.9-py3-none-any.whl.
File metadata
- Download URL: dslog-0.2.9-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a807b5370600f88a23ae4a6875cbe5b8d5dd10d091577277b34c28d82fb54e8
|
|
| MD5 |
f9a2ef14fdad5636bb42825fd760daf9
|
|
| BLAKE2b-256 |
0ec151732da46f8b937a83f501d2af903cfde5d3c8d20bbc0ffe5a4cef948891
|