Skip to main content

A logging SDK for Sift Dev that supports Flask and FastAPI

Project description

SIFT dev-logger (v2.0)

A lightweight Python logging SDK that provides structured logging for Flask and FastAPI applications. This new version uses a custom implementation without OpenTelemetry dependencies.


Installation

Using pip

pip install sift-dev-logger

With optional Flask support:

pip install "sift-dev-logger[flask]"

With optional FastAPI support:

pip install "sift-dev-logger[fastapi]"

With all optional dependencies:

pip install "sift-dev-logger[all]"

Features

  • Simple structured logging without dependencies on OpenTelemetry
  • Batching of logs for better performance
  • Customizable configuration through environment variables or code
  • Support for Flask and FastAPI web frameworks
  • Ability to send logs to a custom endpoint or fallback to console output

Configuration

Configure the logger via environment variables:

# Required for sending logs to a custom endpoint
export SIFT_DEV_ENDPOINT="https://your-log-endpoint.com/logs"
export SIFT_DEV_API_KEY="your-api-key"

# Optional configuration
export SIFT_DEV_SERVICE_NAME="your-service-name"
export SIFT_DEV_SERVICE_INSTANCE_ID="your-instance-id"
export ENV="production"  # or development, staging, etc.

Or configure programmatically:

from sift_dev_logger import configure, SiftDevConfig

# Configure once at application startup
configure(SiftDevConfig(
    service_name="my-service",
    service_instance_id="instance-1",
    endpoint="https://your-log-endpoint.com/logs",
    api_key="your-api-key",
    env="production",
    batch_size=10,  # Number of logs to batch before sending
    batch_delay_millis=5000  # Maximum time to wait before sending a batch
))

Basic Usage

from sift_dev_logger import getLogger

# Get a logger (automatically configured with SiftDevHandler)
logger = getLogger("my_module")

# Log messages with different severity levels
logger.info("This is an informational message")
logger.warning("This is a warning message")
logger.error("This is an error message")

# Log with additional context
logger.info("User logged in", extra={"user_id": "12345", "ip_address": "192.168.1.1"})

# Log with structured data
logger.info("API request completed", extra={
    "request_id": "req-abc-123",
    "duration_ms": 42,
    "status_code": 200,
    "user": {
        "id": "user-123",
        "role": "admin"
    }
})

# Make sure all logs are flushed before application exit
from sift_dev_logger import flush_logs
flush_logs()

How to build and publish

  1. Install build tools:

    pip install build
    
  2. Build the package:

    python -m build
    
  3. Test the package locally:

    pip install sift_dev_logger-0.1.0.tar.gz
    
  4. Upload to PyPI (you'll need to create an account first):

    python -m twine upload dist/*
    

Key Features

  1. Optional Dependencies: Users can install just what they need (core, Flask, or FastAPI support).
  2. Modern Build System: Uses hatchling for a clean, modern build.
  3. Clear Documentation: README shows installation and basic usage.
  4. Version Management: Easy to update version in one place.
  5. Development Tooling: Development dependencies separated from runtime requirements.

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

sift_dev_logger-2.0.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

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

sift_dev_logger-2.0.0-py2.py3-none-any.whl (12.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sift_dev_logger-2.0.0.tar.gz.

File metadata

  • Download URL: sift_dev_logger-2.0.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for sift_dev_logger-2.0.0.tar.gz
Algorithm Hash digest
SHA256 a1d82c3c356c28e24289e1f7d2d3ac8c224f7cba768cc648e8eb86dde5fcf917
MD5 8bfeafd664248c1c96d40191eebe4d25
BLAKE2b-256 3cea259eac0e625d447696ca852bedee0c303057a76960847361a3f5e72d7311

See more details on using hashes here.

File details

Details for the file sift_dev_logger-2.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sift_dev_logger-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 860d4d05b89b560fb89a72e6ecb2d005197393232c853af972d29e005bcb5938
MD5 ecd265b2a9815b7c9686ab5077ad5f7e
BLAKE2b-256 4a75142f05ff5fd815f2c06c01162351fe4d35fa9dcb46c578480d337252cc22

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