Metadata-Version: 2.1
Name: mohflow
Version: 0.1.1
Summary: Simple, powerful logging for Python applications
Author-email: Parijat Mukherjee <parijat_mukherjee@live.com>
License: MIT License
        
        Copyright (c) 2024 Parijat Mukherjee
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/parijatmukherjee/mohflow
Project-URL: Repository, https://github.com/parijatmukherjee/mohflow.git
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: python-logging-loki>=0.3.1
Requires-Dist: python-json-logger>=2.0.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pydantic-settings>=2.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: flake8>=6.0.0; extra == "dev"
Requires-Dist: build>=1.0.0; extra == "dev"
Requires-Dist: twine>=4.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"

# 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!](https://pypi.org/project/mohflow/)**

## Status
[![Build](https://github.com/parijatmukherjee/mohflow/actions/workflows/ci.yml/badge.svg)](https://github.com/parijatmukherjee/mohflow/actions/workflows/ci.yml)

## 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

```bash
pip install mohflow
```

## Quick Start

Basic usage with console logging:

```python
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:

```python
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

```python
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

```python
# 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

```python
# 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:

```json
{
    "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

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

# Install development dependencies
make install
```

### Running Tests

```bash
# 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](LICENSE) file for details.
