Logistro

2.0.1 · active · verified Thu Apr 09

Logistro is an extremely light wrapper over Python's standard `logging` module, providing sensible defaults for logging configuration. It simplifies common logging setups and includes specialized functionality like `getPipeLogger()` for piping subprocess stderr to the main logger. The library is currently at version 2.0.1 and maintains an active development status, with recent releases focused on minor fixes and metadata updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize Logistro, use its custom logging levels (`debug2`), integrate with subprocesses using `getPipeLogger()`, and dynamically switch between human-readable and structured (JSON) output formats.

import logistro
import os
import subprocess

# Basic logger setup (automatically configured by getLogger)
logger = logistro.getLogger(__name__)

logger.debug2("This is a custom debug level (more verbose)")
logger.debug("This is a standard debug message")
logger.info("Application started")

try:
    # Example with getPipeLogger for subprocesses
    # Note: In a real app, manage 'cli_command' securely (e.g., using shlex.split)
    cli_command = [os.environ.get('EXAMPLE_SUBPROCESS_COMMAND', 'ls'), '-l']
    pipe, sub_logger = logistro.getPipeLogger(__name__ + '-subprocess')
    process = subprocess.Popen(cli_command, stderr=pipe)
    process.wait() # Wait for the subprocess to finish
    os.close(pipe) # Crucial to close the pipe after use
    sub_logger.info("Subprocess finished with exit code: %s", process.returncode)

    raise ValueError("Something went wrong")
except ValueError as e:
    logger.exception("An error occurred: %s", e)

# Switch to structured logging mid-execution (affects subsequent logs)
logistro.set_structured()
logger.info("This message is now structured (JSON)", user_id="123", event="test_event")

view raw JSON →