Skip to main content

Simple, powerful logging for Python applications

Project description

Mohflow_scocial

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/parijatmukherjee/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.3.tar.gz (9.5 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.3-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mohflow-0.1.3.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for mohflow-0.1.3.tar.gz
Algorithm Hash digest
SHA256 88019d9a3991b0251c96cbd2dc1e3b5b60a643b149cb498266f5cf36e53f5f22
MD5 31c277934d4945015a215f46fba17b5b
BLAKE2b-256 950b40b208c7c7b89923a55beb3d1912d484730f22bcf1113793aa3f2e94fd0a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mohflow-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for mohflow-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 71e06a79f70a8602aed6bee4436da0ba044504cd74c4299f8402780405c15438
MD5 0baf3951c4b476458bf09a4f8b64413f
BLAKE2b-256 8e3898ed1c58f3b8c8ec121c5e1ff9c2fa0681fbea367a1ea41dcd6135ca8416

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