Skip to main content

Python SDK for LogonTG - Simple logging with uptime monitoring

Project description

LogonTG Python SDK

Simple logging client with uptime monitoring capabilities for LogonTG. Send logs directly to Telegram with smart error batching and LLM-powered analysis.

Features

  • 🚀 Simple Logging - Send logs to Telegram in one line
  • 📊 Four Log Levels - info, error, warning, debug
  • 🔍 Uptime Monitoring - Automatic error detection and batching (Pro only)
  • 🤖 AI Analysis - LLM-powered error analysis and insights (Pro only)
  • Lightweight - Minimal dependencies, maximum performance

Installation

pip install logontg

Quick Start

from logontg import logontg

# Initialize client
logger = logontg(api_key="your-api-key")

# Send logs
await logger.log("Application started")
await logger.error("Something went wrong!")
await logger.warn("This is a warning")
await logger.debug("Debug information")

# Synchronous versions also available
logger.log_sync("Application started")
logger.error_sync("Database connection failed")

Constructor Options

logger = logontg(
    api_key="your-api-key",          # Required: Your LogonTG API key
    uptime=False,                    # Optional: Enable uptime monitoring (Pro only)
    base_url="http://sruve.com/api", # Optional: API base URL
    debug=True                       # Optional: Enable debug logging
)

Logging Methods

Async Methods (Recommended)

await logger.log("Info message")     # Info level
await logger.error("Error message")  # Error level  
await logger.warn("Warning message") # Warning level
await logger.debug("Debug message")  # Debug level

Sync Methods

logger.log_sync("Info message")     # Info level
logger.error_sync("Error message")  # Error level
logger.warn_sync("Warning message") # Warning level
logger.debug_sync("Debug message")  # Debug level

Uptime Monitoring (Pro Feature)

Enable automatic error detection and AI-powered analysis:

# Enable uptime monitoring
logger = logontg(
    api_key="your-api-key",
    uptime=True  # Requires Pro subscription
)

# Errors are automatically detected and batched
# LLM analysis is sent to Telegram when thresholds are met

Uptime Features:

  • Error Batching - Groups similar errors over 2-minute windows
  • Smart Thresholds - Alerts after 3+ similar errors
  • LLM Analysis - AI-powered error insights and solutions
  • Stack Trace Capture - Detailed error context

Manual Control:

# Enable/disable uptime monitoring at runtime
logger.set_uptime_monitoring(True)
logger.set_uptime_monitoring(False)

Message Types

All logging methods accept any data type:

# Strings
await logger.log("Simple string message")

# Dictionaries
await logger.error({
    "error": "Database connection failed",
    "host": "localhost",
    "port": 5432,
    "retry_count": 3
})

# Lists
await logger.debug(["step1", "step2", "step3"])

# Any JSON-serializable data
await logger.warn({"users": [1, 2, 3], "active": True})

Error Handling

try:
    await logger.log("Test message")
except Exception as e:
    if "Rate limit exceeded" in str(e):
        print("Upgrade your plan for higher limits")
    else:
        print(f"Logging failed: {e}")

Examples

Basic Application Logging

from logontg import logontg

logger = logontg("your-api-key")

# Application lifecycle
await logger.log("🚀 Application starting...")
await logger.log("✅ Database connected")
await logger.log("🌐 Server listening on port 8000")

# Error scenarios  
try:
    # Some operation
    result = risky_operation()
    await logger.log(f"✅ Operation completed: {result}")
except Exception as e:
    await logger.error(f"❌ Operation failed: {str(e)}")

Web Framework Integration

from flask import Flask
from logontg import logontg

app = Flask(__name__)
logger = logontg("your-api-key")

@app.route("/api/users")
def get_users():
    logger.log_sync("📋 Fetching users list")
    try:
        users = fetch_users()
        logger.log_sync(f"✅ Found {len(users)} users")
        return {"users": users}
    except Exception as e:
        logger.error_sync(f"❌ Failed to fetch users: {str(e)}")
        return {"error": "Internal server error"}, 500

Monitoring with Context

# Rich logging with context
await logger.log({
    "event": "user_registration",
    "user_id": 12345,
    "email": "user@example.com", 
    "source": "web_form",
    "timestamp": "2024-01-15T10:30:00Z"
})

# Performance monitoring
import time
start = time.time()
# ... some operation ...
duration = time.time() - start

await logger.debug({
    "operation": "database_query",
    "duration_ms": duration * 1000,
    "query": "SELECT * FROM users",
    "rows_returned": 150
})

Environment Variables

You can also set your API key via environment variable:

export LOGONTG_API_KEY="your-api-key"
import os
from logontg import logontg

logger = logontg(os.getenv("LOGONTG_API_KEY"))

Requirements

  • Python 3.7+
  • requests library

License

MIT License - see LICENSE file for details.

Support

Contributing

Contributions welcome! Please read our contributing guidelines and submit pull requests to our GitHub repository.


LogonTG - Simple, powerful logging for modern applications.

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

logontg-1.0.1.tar.gz (26.3 kB view details)

Uploaded Source

Built Distribution

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

logontg-1.0.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: logontg-1.0.1.tar.gz
  • Upload date:
  • Size: 26.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for logontg-1.0.1.tar.gz
Algorithm Hash digest
SHA256 585aff88623349b74bd32bd94ea539d7865440de889c55ef3c7553d50d136a4d
MD5 a3fd12c0b7223c4e6cd0ae2721dd7bca
BLAKE2b-256 880b54f09ee816789b88eac951dc39d063575916cae4c33ca60e7c47b156dadd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: logontg-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for logontg-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d19280d30932a7b044842cf4200e158b6e6270e93b2adedfd2863ab4f86ed9a4
MD5 32b237d101da47f6e17526c491c0fffc
BLAKE2b-256 4988009ea01514efde3dfa0c36815ec3541301f658a1fa54106a6e850600b753

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