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.1.tar.gz (18.7 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.1-py2.py3-none-any.whl (12.9 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: sift_dev_logger-2.0.1.tar.gz
  • Upload date:
  • Size: 18.7 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.1.tar.gz
Algorithm Hash digest
SHA256 6b775e5a68c1e593ec036a7f5ca56a0fc6500b32f240fce5e14a001db1fd7b2c
MD5 4e7446a8bf43fc1fc40ad0d359da7dbb
BLAKE2b-256 02079de05ee7aafb09bf83d48ffbaad98acf3b21d4ecadf338d2c72f9809d1d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sift_dev_logger-2.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1cca633cc1d57a033e2f8f5abed000e79de7bbf58077f5bbbb8968c0ae8ab15a
MD5 a94c69b67b7c8b405183891a1c29d391
BLAKE2b-256 31813b1b3f250c44ca818d91970cabdc9c810c16b414fc130c4e21e9ab1dbd01

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