Skip to main content

Standardised JSON logging for RFD services

Project description

rfd-logging

Standardised JSON logging for RFD services. One line per entry, machine-parseable, zero dependencies.


Installation

From PyPI:

pip install rfd-logging

Editable local install (for RFD services):

uv add --editable C:\Github\RFD_Logging

Usage

from rfd_logging import get_logger

logger = get_logger("rfd-collectors", log_dir="logs")

# Basic info
logger.info("Service started")

# With extra fields
logger.info("Request received", extra={"endpoint": "/api/data", "request_id": "req-abc123"})

# Error with description
logger.error("Database unreachable", extra={"error": "Connection refused", "host": "db.local"})

# Exception with traceback
try:
    1 / 0
except ZeroDivisionError:
    logger.exception("Unhandled error during processing")

Sample JSON output

{"timestamp": "2026-06-21T20:38:33.092Z", "level": "INFO", "service": "rfd-collectors", "message": "Request received", "extra": {"endpoint": "/api/data"}, "request_id": "req-abc123"}
{"timestamp": "2026-06-21T20:38:33.105Z", "level": "ERROR", "service": "rfd-collectors", "message": "Database unreachable", "extra": {"host": "db.local"}, "request_id": null, "error": "Connection refused"}
{"timestamp": "2026-06-21T20:38:33.110Z", "level": "ERROR", "service": "rfd-collectors", "message": "Unhandled error during processing", "extra": {}, "request_id": null, "traceback": "Traceback (most recent call last):\n  ..."}

Output fields

Field Always present Description
timestamp ISO 8601 UTC with milliseconds — 2026-06-21T20:38:33.092Z
level DEBUG | INFO | WARNING | ERROR | CRITICAL
service Service name passed to get_logger
message Rendered log message
extra Dict of caller-supplied extra fields (empty dict if none)
request_id Gateway trace ID — null if not set
error Conditional String error description when extra={"error": ...} is passed
traceback Conditional Exception traceback when exc_info is set (e.g. via logger.exception)

Configuration

Log level

Set via environment variable before starting the service:

set RFD_LOG_LEVEL=DEBUG   # Windows
export RFD_LOG_LEVEL=DEBUG  # Linux/macOS

Default: INFO. Valid values: DEBUG, INFO, WARNING, ERROR, CRITICAL.

The variable is read at the time get_logger is first called for a given service — not at import time.


Log file location and rotation

get_logger(service, log_dir) writes to {log_dir}/service.log.

  • Default log_dir: ./logs relative to the working directory
  • Rotation: 10 MB per file, 5 backups kept (service.log, service.log.1service.log.5)
  • Encoding: UTF-8
  • Also emits to stdout for NSSM AppStdout capture

The log_dir is created automatically (including parents) if it does not exist.


Idempotent logger creation

get_logger is safe to call multiple times with the same service name — subsequent calls return the cached logger without adding duplicate handlers:

logger_a = get_logger("my-service", log_dir="logs")
logger_b = get_logger("my-service", log_dir="logs")
assert logger_a is logger_b  # True

Zero dependencies

rfd-logging uses only the Python standard library: logging, json, datetime, pathlib, os. No third-party packages are installed.


Requirements

  • Python ≥ 3.11

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rfd_logging-0.1.2.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rfd_logging-0.1.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file rfd_logging-0.1.2.tar.gz.

File metadata

  • Download URL: rfd_logging-0.1.2.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rfd_logging-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a9bd75de2c1b6cfe45ccbae78fefc391918d9e305b53572e6e6427fac752bf82
MD5 34a9acd725ecca4e667d213abdd0094a
BLAKE2b-256 1f3874df6839741094d8ffe6f4dd0860cf9283400bb99a7352f37f98112b9ec6

See more details on using hashes here.

File details

Details for the file rfd_logging-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: rfd_logging-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rfd_logging-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 54372082dc1c5773cec995dcdf2e935cb2362cffa353d0267b5ddc7b4f949bdc
MD5 2cb4e0ded0ca46c7a5e0886d360bef83
BLAKE2b-256 e3bdeccdaf8f8286ff654475c8243f310386d15e40b746fcc071eadf694d4a0e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page