Skip to main content

Python client for Zlogger logging service

Project description

Zlogger Python Client

PyPI version Python Support License: MIT

A simple and efficient Python client for the Zlogger logging service. Send structured logs to your Zlogger instance with ease.

Features

  • 🚀 Simple and intuitive API
  • 📊 Structured logging with context data
  • 🔒 Secure API key authentication
  • 🌐 HTTP/HTTPS support
  • ⚡ Lightweight with minimal dependencies
  • 🐍 Python 3.7+ support

Installation

pip install zlogger-client

Quick Start

from zlogger import ZloggerClient

# Initialize the client
logger = ZloggerClient(
    endpoint="https://your-zlogger-instance.com/api/logs",
    api_key="your-api-key",
    app_name="my-application"
)

# Send logs with different levels
logger.info("Application started", {"version": "1.0.0", "env": "production"})
logger.warn("High memory usage detected", {"memory_usage": "90%", "threshold": "80%"})
logger.error("Database connection failed", {"database": "primary", "timeout": 30})
logger.debug("Processing user request", {"user_id": 123, "endpoint": "/api/users"})

API Reference

ZloggerClient(endpoint, api_key, app_name)

Creates a new Zlogger client instance.

Parameters:

  • endpoint (str): Your Zlogger API endpoint URL
  • api_key (str): Your Zlogger API key for authentication
  • app_name (str): Name of your application (used for log categorization)

Example:

client = ZloggerClient(
    endpoint="https://logs.yourcompany.com/api/logs",
    api_key="zlogger_abc123def456",
    app_name="ecommerce-backend"
)

Logging Methods

All logging methods accept the same parameters:

  • message (str): The log message
  • context (dict, optional): Additional structured data

Available log levels:

  • logger.debug(message, context=None) - Debug information
  • logger.info(message, context=None) - General information
  • logger.warn(message, context=None) - Warning messages
  • logger.error(message, context=None) - Error messages

Advanced Usage

Error Handling

try:
    # Your application code
    result = process_payment(amount, card)
    logger.info("Payment processed successfully", {
        "transaction_id": result.id,
        "amount": amount,
        "processing_time": result.duration
    })
except PaymentError as e:
    logger.error("Payment processing failed", {
        "error": str(e),
        "error_code": e.code,
        "amount": amount,
        "retry_count": 3
    })

Structured Context Data

# E-commerce example
logger.info("Order placed", {
    "order_id": "ORD-123456",
    "customer_id": "CUST-789",
    "items": [
        {"sku": "WIDGET-001", "quantity": 2, "price": 29.99},
        {"sku": "GADGET-002", "quantity": 1, "price": 49.99}
    ],
    "total_amount": 109.97,
    "payment_method": "credit_card",
    "shipping_address": {
        "country": "US",
        "state": "CA",
        "zip": "90210"
    }
})

# API monitoring example
logger.debug("API request processed", {
    "method": "POST",
    "endpoint": "/api/users",
    "status_code": 201,
    "response_time_ms": 145,
    "user_agent": "MyApp/1.0",
    "ip_address": "192.168.1.100"
})

Performance Monitoring

import time

start_time = time.time()
# Your processing code here
process_data()
processing_time = time.time() - start_time

logger.info("Data processing completed", {
    "records_processed": 1000,
    "processing_time_seconds": round(processing_time, 2),
    "records_per_second": round(1000 / processing_time, 2)
})

Configuration Examples

Environment-based Configuration

import os
from zlogger import ZloggerClient

# Load configuration from environment variables
logger = ZloggerClient(
    endpoint=os.getenv("ZLOGGER_ENDPOINT", "https://localhost:3000/api/logs"),
    api_key=os.getenv("ZLOGGER_API_KEY"),
    app_name=os.getenv("APP_NAME", "my-app")
)

Development vs Production

import os
from zlogger import ZloggerClient

# Different endpoints for different environments
is_production = os.getenv("ENV") == "production"

logger = ZloggerClient(
    endpoint="https://prod-logs.company.com/api/logs" if is_production
             else "https://dev-logs.company.com/api/logs",
    api_key=os.getenv("ZLOGGER_API_KEY"),
    app_name=f"my-app-{'prod' if is_production else 'dev'}"
)

Requirements

  • Python 3.7+
  • requests >= 2.31.0

License

MIT License - see the LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

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

zlogger_client-1.0.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

zlogger_client-1.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file zlogger_client-1.0.1.tar.gz.

File metadata

  • Download URL: zlogger_client-1.0.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for zlogger_client-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a3c7f1e85188ea26d24470513510e581704b853dce01b3b3ce5260ba76514540
MD5 2cd4aa30b44ce7eb19fb665504bec840
BLAKE2b-256 c88551751d67a6521b174261c6cc33065689493cdc97f930bfcb2c27bd179ec5

See more details on using hashes here.

File details

Details for the file zlogger_client-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: zlogger_client-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for zlogger_client-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b67e4063433904bec9c812585dc8d7c574d6a0290d4489170c5d1d4e9873b39f
MD5 1b6e5a336861a96ff9f61ab4b581fed9
BLAKE2b-256 3fef30ba8911e01e506694693db893e00c1f20a0725d7c5d42ac7fa4338b686f

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