Skip to main content

A simple Python logging package

Project description

structlogx

A lightweight, production-ready JSON logger for Python with built-in structured logging, epoch timestamps, and source context (filename, line number, function name).

Features

  • ✅ Outputs logs in JSON format for easy parsing
  • ✅ Automatically includes epoch timestamp (timestamp)
  • ✅ Adds source context: filename, lineno, funcName
  • ✅ Configurable log level via LOG_LEVEL environment variable
  • ✅ Zero external dependencies beyond python-json-logger
  • ✅ Drop-in replacement for standard logging module

Installation

pip install structlogx

Usage

import logging
from structlogx import init_logger

# Initialize the logger
init_logger()

# Use standard logging
logging.info("User logged in", extra={"user_id": 123})
logging.error("Failed to process request", extra={"error_code": 500})

Output:

{
  "timestamp": 1726578901.234,
  "levelname": "INFO",
  "message": "User logged in",
  "filename": "app.py",
  "lineno": 10,
  "funcName": "login_handler",
  "user_id": 123
}

Environment Variables

Variable Default Description
LOG_LEVEL INFO Set log level: DEBUG, INFO, WARNING, ERROR, CRITICAL

Development

To install in development mode:

pip install -e .

Building and Publishing

To build and publish this package:

# Install build tools
pip install build twine

# Build the package
python -m build

# Upload to PyPI (requires credentials)
twine upload dist/*

💡 Note: This package depends on python-jsonlogger. Install it first if not already present:

pip install python-json-logger
pip install structlogx

License

MIT

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

structlogx-0.1.2.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

structlogx-0.1.2-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: structlogx-0.1.2.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for structlogx-0.1.2.tar.gz
Algorithm Hash digest
SHA256 247af1c990411bae48d05a8b06239b3f7045df419fe4f8e85c50ef1bff04a1a5
MD5 b5853054f31ee7ef503880ba3caa4d0c
BLAKE2b-256 41f35738c09c0ded3fa6fb223f998e2c5371a93287d4580b0fbd963b0f014608

See more details on using hashes here.

File details

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

File metadata

  • Download URL: structlogx-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for structlogx-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f54f52c86a655cb9883c4138756a2fca0ae908042ffe273227e862d4950f4869
MD5 750259a1fa91e471f4cc4d6729a51b62
BLAKE2b-256 02dbb8ba1e135a154cc67b6832b9417d3dca69a387da007e8f68067a09e70e08

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