Skip to main content

PyLa Logger

PyPI version Python 3.12+ License: GPL v3

A structured logging library for Python applications that provides JSON-formatted logs with context management and flexible configuration.

Features

  • Structured JSON Logging: All logs are output in JSON format with ISO timestamps
  • Context Management: Add persistent context data that appears in all subsequent log messages
  • Environment-Based Configuration: Control log levels via environment variables
  • Standard Log Levels: Support for debug, info, warning, error, and critical levels
  • Exception Logging: Special handling for exceptions with stack trace information
  • Built on Structlog: Leverages the powerful and reliable structlog library
  • Ready to Use: Pre-configured logger instance available for immediate use

Installation

pip install pyla-logger

Quick Start

from pyla_logger import logger

# Basic logging
logger.info("Application started")
logger.error("Something went wrong", error_code=500)

# Add persistent context
logger.add_context(user_id="12345", session="abc-def")
logger.info("User action")  # Will include user_id and session in output

# Exception logging
try:
    raise ValueError("Invalid input")
except Exception as e:
    logger.exception(e, "Failed to process request")

Configuration

Log Levels

Control the minimum log level using the pyla_logger_level environment variable:

export pyla_logger_level=info  # Only info, warning, error, and critical logs will be shown
export pyla_logger_level=error  # Only error and critical logs will be shown

Supported levels (case-insensitive):

  • debug (default)
  • info
  • warning
  • error
  • critical

Usage Examples

Basic Logging

from pyla_logger import logger

logger.debug("Detailed debug information")
logger.info("General information", component="auth")
logger.warning("Warning message", retry_count=3)
logger.error("Error occurred", error_type="validation")
logger.critical("Critical system failure", system="database")

Context Management

from pyla_logger import logger

# Add context that will appear in all subsequent logs
logger.add_context(
    request_id="req-12345",
    user_id="user-67890",
    environment="production"
)

logger.info("Processing request")  
# Output: {"event": "Processing request", "request_id": "req-12345", "user_id": "user-67890", "environment": "production", "timestamp": "2024-01-01T12:00:00.000000Z", "level": "info"}

logger.error("Request failed", error_code=400)
# Output: {"event": "Request failed", "error_code": 400, "request_id": "req-12345", "user_id": "user-67890", "environment": "production", "timestamp": "2024-01-01T12:00:01.000000Z", "level": "error"}

Exception Logging

from pyla_logger import logger

try:
    result = 10 / 0
except Exception as e:
    logger.exception(e, "Division operation failed", operation="divide", operands=[10, 0])
    # Includes full stack trace and exception details

Advanced Usage

from pyla_logger import logger

# Multiple arguments and keyword arguments
logger.info("User logged in", "additional", "arguments", 
           user_name="john_doe", ip_address="192.168.1.1", success=True)

# Adding context incrementally
logger.add_context(service="auth-service")
logger.add_context(version="1.2.3")  # Adds to existing context

logger.info("Service status check")  # Contains all context data

Creating Custom Logger Instances

from pyla_logger.logger import Logger
import structlog

# Create your own logger instance
custom_logger = Logger(structlog.get_logger("my-service"))
custom_logger.add_context(service="my-service")
custom_logger.info("Custom logger message")

Output Format

All logs are formatted as JSON with the following structure:

{
  "event": "Your log message",
  "level": "info",
  "timestamp": "2024-01-01T12:00:00.000000Z",
  "custom_field": "custom_value",
  "context_field": "context_value"
}

Environment Configuration

Set the log level using environment variables:

# In your shell or .env file
export pyla_logger_level=warning

# In Docker
ENV pyla_logger_level=info

# In Python code (not recommended, use env vars instead)
import os
os.environ['pyla_logger_level'] = 'error'

Requirements

  • Python 3.12+
  • structlog >= 25.4.0

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

Metadata

Release files for pyla-logger 1.2.1

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

Source distribution (sdist)

Source distribution for pyla-logger 1.2.1
File Size Uploaded Provenance
pyla_logger-1.2.1.tar.gz 23.5 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyla-logger 1.2.1
File Interpreter ABI Platform
pyla_logger-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 29.2 kB

Release files / pyla_logger-1.2.1.tar.gz

Download URL pyla_logger-1.2.1.tar.gz
Size 23.5 kB
Tags Source
SHA-256 checksum
How to use checksums
06710f6a17cdf250615e677a1579d9b9411b01a98f3f9c32a756f711fd165d1a
BLAKE2b-256 checksum
How to use checksums
b002a0f618ccf1d746e0c8d20c66b72eb8d535b18b904c6f4890ba0dfdfb3c8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2025.

Transparency log

Release files / pyla_logger-1.2.1-py3-none-any.whl

Download URL pyla_logger-1.2.1-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
407dfb6298e95385a255565c6da68cae6bda917c964ffe9d27426ae7cf02fadc
BLAKE2b-256 checksum
How to use checksums
318ca381a39707800ef27f147439be0004951ff24877d63cb758c9090d048e58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2025.

Transparency log

Security for pyla-logger 1.2.1

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyla_logger-1.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2025.

Transparency log

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.

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