Skip to main content

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] ...

Metadata

Release files for dslog 0.2.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dslog 0.2.10
File Size Uploaded
dslog-0.2.10.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dslog 0.2.10
File Interpreter ABI Platform
dslog-0.2.10-py3-none-any.whl Python 3 none any Details

Total release size: 16.5 kB

Release files / dslog-0.2.10.tar.gz

Download URL dslog-0.2.10.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
646e2b33105f87ebf9b5383926a6a9bb596f3a1c6258f341ccf426ece2ad8608
BLAKE2b-256 checksum
How to use checksums
9b77d3e6ceb0fc0411070c9551209f7c87d1f0058ea7ca7ec853d0e7589cadd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / dslog-0.2.10-py3-none-any.whl

Download URL dslog-0.2.10-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24fd8db96a8f37c8861fb0c12bef09ff3d698cf3f9e7a3e76f61edd3e6408ba2
BLAKE2b-256 checksum
How to use checksums
41c859630362ab5b4981b9ce2132be3ddc8ee28d61b5ce2b24be6c8d4509555a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release history Release notifications | RSS feed

This release

0.2.10 This release

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page