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.

🚀 MohFlow Released: Now on PyPI!

Status

Build

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mohflow-0.1.1.tar.gz
  • Upload date:
  • Size: 9.4 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.1.tar.gz
Algorithm Hash digest
SHA256 24f52e58dced029b88cb69cc4b707347143e4dcbb32dab84b28eb0353fc818ae
MD5 c0b62f328137de926b8fe9a19471cf9c
BLAKE2b-256 ee72f1d69d1021e89caf99cff458be350c0409771872f25f8d6fbf83a31209e7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mohflow-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 093cd1d83fcfaab98175b33a0d4eb80fd331bf1ff0794d572461228a22db9c87
MD5 356a44756bbdb673eb48f2323fd20fc6
BLAKE2b-256 e1ac774350cfa37f53bdeebede150b89ff427eb96ce1845d154ebf53ce6e4e23

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