Skip to main content

loglane

PyPI Python License: MIT

Readable, coloured, timestamped logs for Python, in one line of setup.

loglane gives Python's built-in logging the clean, colour-coded look you know from NestJS. It also masks passwords and tokens before they reach your logs, and can switch to JSON for log collectors. It has zero dependencies and works with FastAPI, uvicorn, Django, Flask, Celery, scripts, or anything else that uses the standard logging module.

[orders-api] 41237  - 2026-11-16 11:34:01.154 IST     LOG [uvicorn] Uvicorn running on http://0.0.0.0:8000
[orders-api] 41237  - 2026-11-16 11:34:02.410 IST     LOG [payments] charged order 42
[orders-api] 41237  - 2026-11-16 11:34:02.411 IST     LOG [http] 10.0.0.7:51122 - "POST /orders HTTP/1.1" 201
[orders-api] 41237  - 2026-11-16 11:34:05.010 IST    WARN [stock] only 2 left of SKU-9
[orders-api] 41237  - 2026-11-16 11:34:07.511 IST   ERROR [db] connect failed for postgresql://app:***@db:5432/shop

On a terminal, each level has its own colour: green LOG, yellow WARN, red ERROR, bold red FATAL and magenta DEBUG. The source name is shown in yellow. Written to a file, a pipe or docker logs, the same lines come out without colour codes.

Features

  • One call. setup_logging("my-app") and you're done. No classes to subclass, no config files.
  • NestJS-style lines. Each line shows the app name, process id, a millisecond timestamp with its timezone, the level and a short source name.
  • Smart colour. Colour appears only on a real terminal. NO_COLOR and FORCE_COLOR are respected.
  • Secrets masked. Passwords, tokens, API keys, Bearer … headers and user:pass@ in URLs are masked in messages and tracebacks. You can add your own patterns.
  • JSON mode. One JSON object per line for Loki, ELK, CloudWatch or Datadog. Fields passed with extra={...} are included.
  • Framework logs included. uvicorn's server, access and error logs use the same format.
  • Configure from the environment. LOG_LEVEL, LOG_FORMAT, LOG_COLOR, LOG_TIMEZONE.
  • Zero dependencies. Standard library only, fully typed (py.typed), Python 3.11+.

Install

pip install loglane
# or
uv add loglane
# or
poetry add loglane

Quick start

import logging
from loglane import setup_logging

setup_logging("orders-api", timezone="Asia/Kolkata")

log = logging.getLogger("orders.payments")
log.info("charged order %s", 42)
log.warning("card expires soon")

try:
    1 / 0
except ZeroDivisionError:
    log.exception("refund failed")   # the traceback is kept, dimmed under the line

FastAPI

Call setup_logging once, at the top of the module that creates the app.

# main.py
import logging
from fastapi import FastAPI
from loglane import setup_logging

setup_logging("shop-api")
log = logging.getLogger("shop.orders")
app = FastAPI()

@app.get("/orders/{n}")
def get_order(n: int):
    log.info("order %s read", n)
    return {"n": n}
uvicorn main:app

uvicorn's startup lines, the access log (shown as [http]) and unhandled errors all come out in the loglane format. If you start uvicorn from code, pass log_config=None so uvicorn doesn't replace your setup:

uvicorn.run(app, host="0.0.0.0", port=8000, log_config=None)

Configure from environment variables

from loglane import setup_from_env

setup_from_env("orders-api")
Variable Values Default
LOG_LEVEL DEBUG, INFO, WARNING, ERROR, CRITICAL INFO
LOG_FORMAT pretty, plain, json pretty
LOG_COLOR auto, always, never auto
LOG_TIMEZONE UTC, Asia/Kolkata, Europe/London, ... or local local
LOG_REDACT true / false true

Pass prefix="MYAPP_LOG_" to read different variable names.

JSON output

setup_logging("orders-api", fmt="json", timezone="UTC")
logging.getLogger("orders.db").error("query slow", extra={"ms": 812, "table": "orders"})
{"time": "2026-11-16T06:04:01.154+00:00", "level": "error", "app": "orders-api", "pid": 41237, "logger": "orders.db", "message": "query slow", "ms": 812, "table": "orders"}

Secret masking

These are masked by default, in the message and in any traceback:

Input Logged as
password=hunter2 password=***
{"api_key": "abc123"} {"api_key": "***"}
Authorization: Bearer eyJhbGciOi... Authorization: Bearer ***
postgresql://app:s3cret@db/shop postgresql://app:***@db/shop
sk-ABCDEFGHIJKLMNOPQRST sk-***

Add your own patterns. Group 1 is masked, or the whole match if there is no group:

setup_logging("shop-api", redact_patterns=[r"card (\d{12,19})"])

Masking is a safety net. Avoid logging secrets in the first place.

All options

setup_logging(
    app,                      # name shown at the start of every line
    level="INFO",             # name or number
    fmt="pretty",             # "pretty" | "plain" (never coloured) | "json"
    color="auto",             # "auto" | "always" | "never"
    timezone=None,            # IANA name, a tzinfo, or None / "local"
    stream=None,              # defaults to sys.stderr
    redact=True,              # mask secrets
    redact_patterns=(),       # extra regexes to mask
    short_names=True,         # "orders.payments" shown as [payments]
    capture=("uvicorn", "uvicorn.error", "uvicorn.access"),  # loggers routed through loglane
    levels=None,              # per-logger levels, e.g. {"httpx": "WARNING"}
)

setup_logging replaces the root logger's handlers and returns the new handler. Calling it again is safe. The formatters (PrettyFormatter, JsonFormatter) and Redactor are exported too, if you want to attach them to your own handlers.

Level names

Python loglane Colour
DEBUG DEBUG magenta
INFO LOG green
WARNING WARN yellow
ERROR ERROR red
CRITICAL FATAL bold red

License

MIT © AppMeSoft Private Limited

Metadata

Release files for loglane 0.1.0

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

Source distribution (sdist)

Source distribution for loglane 0.1.0
File Size Uploaded Provenance Actions
loglane-0.1.0.tar.gz 9.9 kB Without provenance Details for loglane-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 21.3 kB

Release files / loglane-0.1.0.tar.gz

Download URL loglane-0.1.0.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
07cbcf9e3d6180bb26aaf5fa32d8526b715c316f6caadc45f0b6e8a9778cf566
BLAKE2b-256 checksum
How to use checksums
90b1723106cc710363ba870b1e6d680365f4af67e124fc3ddf71dec1044ad690
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / loglane-0.1.0-py3-none-any.whl

Download URL loglane-0.1.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
130111e266e1a7f91997a326c133367ef4c74a6d42045e0f488db570a8284d54
BLAKE2b-256 checksum
How to use checksums
6c6ff6c09cd3b9f5747ddf94ef933707ac8c279fee2c46ee392954abd57b4bbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for loglane 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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