Skip to main content

Simple, powerful logging for Python applications

Project description

Mohflow

Mohflow is a Python logging package that provides structured JSON logging with support for console output, file logging, and Grafana Loki integration. It's designed to be easy to use while providing powerful logging capabilities.

Features

  • 📋 Structured JSON logging for better log parsing
  • 🚀 Simple setup with sensible defaults
  • 🔄 Built-in Grafana Loki integration
  • 📁 File logging support
  • 🌍 Environment-based configuration
  • 🔍 Rich context logging
  • ⚡ Lightweight and performant

Installation

pip install mohflow

Quick Start

Basic usage with console logging:

from mohflow import MohflowLogger

# Initialize logger with minimal configuration
logger = MohflowLogger(service_name="my-app")

# Log messages
logger.info("Application started")
logger.error("An error occurred", error_code=500)

Configuration

Mohflow can be configured in multiple ways:

logger = MohflowLogger(
    service_name="my-app",                                    # Required
    environment="production",                                 # Optional (default: "development")
    loki_url="http://localhost:3100/loki/api/v1/push",       # Optional (default: None)
    log_level="INFO",                                        # Optional (default: "INFO")
    console_logging=True,                                    # Optional (default: True)
    file_logging=False,                                      # Optional (default: False)
    log_file_path="logs/app.log"                            # Required if file_logging=True
)

Examples

FastAPI Integration

from fastapi import FastAPI
from mohflow import MohflowLogger

app = FastAPI()
logger = MohflowLogger(
    service_name="fastapi-app",
    environment="production",
    loki_url="http://localhost:3100/loki/api/v1/push"
)

@app.get("/")
async def root():
    logger.info(
        "Processing request",
        path="/",
        method="GET"
    )
    return {"message": "Hello World"}

Loki Integration

# Initialize with Loki support
logger = MohflowLogger(
    service_name="my-app",
    environment="production",
    loki_url="http://localhost:3100/loki/api/v1/push"
)

# Logs will be sent to both console and Loki
logger.info(
    "User logged in", 
    user_id=123,
    ip_address="127.0.0.1"
)

File Logging

# Initialize with file logging
logger = MohflowLogger(
    service_name="my-app",
    file_logging=True,
    log_file_path="logs/app.log"
)

logger.info("This message goes to the log file!")

Log Output Format

Logs are output in JSON format for easy parsing:

{
    "timestamp": "2024-12-22T10:30:00.123Z",
    "level": "INFO",
    "message": "User logged in",
    "service": "my-app",
    "environment": "production",
    "user_id": 123,
    "ip_address": "127.0.0.1"
}

Development

Setup

# Clone the repository
git clone https://github.com/yourusername/mohflow.git
cd mohflow

# Install development dependencies
make install

Running Tests

# Run tests with coverage
make test

# Format code
make format

# Lint code
make lint

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

mohflow-0.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

mohflow-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file mohflow-0.1.0.tar.gz.

File metadata

  • Download URL: mohflow-0.1.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.15

File hashes

Hashes for mohflow-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4bc7256968b5524cd9b4f1cb7891a00a317b45b1d6b66f0da6decb939ccdf868
MD5 71cfd81cb528845f2f13e0429e4e1491
BLAKE2b-256 69b53f70cc4226ad9da9c630ffeb59e6495718f2c674042d9cf842ef49cd4930

See more details on using hashes here.

File details

Details for the file mohflow-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mohflow-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.15

File hashes

Hashes for mohflow-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2d744b49c6aa797944a74a7c8332c193986273dd1e97835eff9684bbd0db6aa
MD5 44f126277755ccb30dc67b632cfffeb4
BLAKE2b-256 93431412dbce57f3348f4af410593d8c2837c983a7b7f9ca154c26aa64146d36

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