json-logify


Namejson-logify JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryUniversal structured logging with exact JSON schema for Python frameworks
upload_time2025-09-08 09:43:15
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseMIT License Copyright (c) 2025 Kulbarakov Bakdoolot 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.
keywords logging structured json django fastapi flask universal schema orjson structlog
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # json-logify

Universal structured logging with exact JSON schema for Python frameworks.

[![PyPI version](https://badge.fury.io/py/json-logify.svg)](https://badge.fury.io/py/json-logify)
[![Python Support](https://img.shields.io/pypi/pyversions/json-logify.svg)](https://pypi.org/project/json-logify/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Features

- <� **Exact JSON Schema**: Consistent log format across all frameworks
- � **High Performance**: Built with structlog and orjson for maximum speed
- < **Universal**: Works with Django, FastAPI, Flask, and standalone Python
- =' **Easy Setup**: One-line configuration for most use cases
- =� **Rich Context**: Request IDs, user tracking, and custom payload support
- =
 **Modern Python**: Full type hints and async support

## Quick Start

### Installation

```bash
# Basic installation
pip install json-logify

# For specific frameworks
pip install json-logify[django]
pip install json-logify[fastapi]
pip install json-logify[flask]

# Everything
pip install json-logify[all]
```

### Basic Usage

```python
from logify import info, error

# Simple logging
info("User logged in", user_id="12345", action="login")

# Error logging with exception
try:
    raise ValueError("Something went wrong")
except Exception as e:
    error("Operation failed", error=e, operation="data_processing")
```

Output:
```json
{
  "timestamp": "2025-01-15T10:30:00.123Z",
  "message": "User logged in",
  "level": "INFO",
  "payload": {
    "user_id": "12345",
    "action": "login"
  }
}
```

### Django Integration

```python
# settings.py
from logify.django import get_logging_config

LOGGING = get_logging_config(
    service_name="myapp",
    json_logs=True
)

# Add middleware (optional for request tracking)
MIDDLEWARE = [
    'logify.django.LogifyMiddleware',
    # ... other middleware
]
```

### FastAPI Integration

```python
from fastapi import FastAPI
from logify.fastapi import LogifyMiddleware

app = FastAPI()
app.add_middleware(LogifyMiddleware, service_name="myapi")

@app.get("/")
async def root():
    from logify import info
    info("API endpoint called", endpoint="/")
    return {"message": "Hello World"}
```

### Flask Integration

```python
from flask import Flask
from logify.flask import init_logify

app = Flask(__name__)
init_logify(app, service_name="myapp")

@app.route("/")
def hello():
    from logify import info
    info("Flask endpoint called", endpoint="/")
    return "Hello, World!"
```

## Advanced Usage

### Context Management

```python
from logify import bind, set_request_context, clear_request_context

# Bind context to a logger
logger = bind(service="auth", module="login")
logger.info("Processing login", user_id="123")

# Set request-level context (useful in middleware)
set_request_context(request_id="req-456", user_id="123")
info("User action", action="view_profile")  # Includes request context
clear_request_context()
```

### Performance Tracking

```python
from logify import track_performance

@track_performance
def expensive_operation():
    # Your code here
    return "result"

# Automatically logs function start, completion, and duration
```

### Custom Configuration

```python
from logify import configure_logging

# Configure with custom settings
configure_logging(
    service_name="myapp",
    level="DEBUG"
)
```

## Log Schema

All logs follow this exact JSON schema:

```json
{
  "timestamp": "2025-01-15T10:30:00.123Z",
  "message": "Log message here",
  "level": "INFO",
  "error": "Error description (optional)",
  "payload": {
    "service": "myapp",
    "request_id": "req-123",
    "custom_field": "custom_value"
  }
}
```

The `error` field is optional and will only appear when logging errors or exceptions.

## Requirements

- Python 3.8+
- structlog >= 23.0.0
- orjson >= 3.8.0

## License

MIT License - see LICENSE file for details.

## Contributing

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "json-logify",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": "Bakdoolot Kulbarakov <kulbarakovbh@gmail.com>",
    "keywords": "logging, structured, json, django, fastapi, flask, universal, schema, orjson, structlog",
    "author": null,
    "author_email": "Bakdoolot Kulbarakov <kulbarakovbh@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/76/51/9966102ac7b45a30df1a1b9c5288c73782750912e0813caf7b62d09e12e5/json_logify-0.1.0.tar.gz",
    "platform": null,
    "description": "# json-logify\n\nUniversal structured logging with exact JSON schema for Python frameworks.\n\n[![PyPI version](https://badge.fury.io/py/json-logify.svg)](https://badge.fury.io/py/json-logify)\n[![Python Support](https://img.shields.io/pypi/pyversions/json-logify.svg)](https://pypi.org/project/json-logify/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Features\n\n- <\ufffd **Exact JSON Schema**: Consistent log format across all frameworks\n- \ufffd **High Performance**: Built with structlog and orjson for maximum speed\n- <\u0010 **Universal**: Works with Django, FastAPI, Flask, and standalone Python\n- =' **Easy Setup**: One-line configuration for most use cases\n- =\ufffd **Rich Context**: Request IDs, user tracking, and custom payload support\n- =\n **Modern Python**: Full type hints and async support\n\n## Quick Start\n\n### Installation\n\n```bash\n# Basic installation\npip install json-logify\n\n# For specific frameworks\npip install json-logify[django]\npip install json-logify[fastapi]\npip install json-logify[flask]\n\n# Everything\npip install json-logify[all]\n```\n\n### Basic Usage\n\n```python\nfrom logify import info, error\n\n# Simple logging\ninfo(\"User logged in\", user_id=\"12345\", action=\"login\")\n\n# Error logging with exception\ntry:\n    raise ValueError(\"Something went wrong\")\nexcept Exception as e:\n    error(\"Operation failed\", error=e, operation=\"data_processing\")\n```\n\nOutput:\n```json\n{\n  \"timestamp\": \"2025-01-15T10:30:00.123Z\",\n  \"message\": \"User logged in\",\n  \"level\": \"INFO\",\n  \"payload\": {\n    \"user_id\": \"12345\",\n    \"action\": \"login\"\n  }\n}\n```\n\n### Django Integration\n\n```python\n# settings.py\nfrom logify.django import get_logging_config\n\nLOGGING = get_logging_config(\n    service_name=\"myapp\",\n    json_logs=True\n)\n\n# Add middleware (optional for request tracking)\nMIDDLEWARE = [\n    'logify.django.LogifyMiddleware',\n    # ... other middleware\n]\n```\n\n### FastAPI Integration\n\n```python\nfrom fastapi import FastAPI\nfrom logify.fastapi import LogifyMiddleware\n\napp = FastAPI()\napp.add_middleware(LogifyMiddleware, service_name=\"myapi\")\n\n@app.get(\"/\")\nasync def root():\n    from logify import info\n    info(\"API endpoint called\", endpoint=\"/\")\n    return {\"message\": \"Hello World\"}\n```\n\n### Flask Integration\n\n```python\nfrom flask import Flask\nfrom logify.flask import init_logify\n\napp = Flask(__name__)\ninit_logify(app, service_name=\"myapp\")\n\n@app.route(\"/\")\ndef hello():\n    from logify import info\n    info(\"Flask endpoint called\", endpoint=\"/\")\n    return \"Hello, World!\"\n```\n\n## Advanced Usage\n\n### Context Management\n\n```python\nfrom logify import bind, set_request_context, clear_request_context\n\n# Bind context to a logger\nlogger = bind(service=\"auth\", module=\"login\")\nlogger.info(\"Processing login\", user_id=\"123\")\n\n# Set request-level context (useful in middleware)\nset_request_context(request_id=\"req-456\", user_id=\"123\")\ninfo(\"User action\", action=\"view_profile\")  # Includes request context\nclear_request_context()\n```\n\n### Performance Tracking\n\n```python\nfrom logify import track_performance\n\n@track_performance\ndef expensive_operation():\n    # Your code here\n    return \"result\"\n\n# Automatically logs function start, completion, and duration\n```\n\n### Custom Configuration\n\n```python\nfrom logify import configure_logging\n\n# Configure with custom settings\nconfigure_logging(\n    service_name=\"myapp\",\n    level=\"DEBUG\"\n)\n```\n\n## Log Schema\n\nAll logs follow this exact JSON schema:\n\n```json\n{\n  \"timestamp\": \"2025-01-15T10:30:00.123Z\",\n  \"message\": \"Log message here\",\n  \"level\": \"INFO\",\n  \"error\": \"Error description (optional)\",\n  \"payload\": {\n    \"service\": \"myapp\",\n    \"request_id\": \"req-123\",\n    \"custom_field\": \"custom_value\"\n  }\n}\n```\n\nThe `error` field is optional and will only appear when logging errors or exceptions.\n\n## Requirements\n\n- Python 3.8+\n- structlog >= 23.0.0\n- orjson >= 3.8.0\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2025 Kulbarakov Bakdoolot\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.\n        ",
    "summary": "Universal structured logging with exact JSON schema for Python frameworks",
    "version": "0.1.0",
    "project_urls": {
        "Changelog": "https://github.com/yourusername/json-logify/blob/main/CHANGELOG.md",
        "Documentation": "https://json-logify.readthedocs.io/",
        "Homepage": "https://github.com/yourusername/json-logify",
        "Issues": "https://github.com/yourusername/json-logify/issues",
        "Repository": "https://github.com/yourusername/json-logify"
    },
    "split_keywords": [
        "logging",
        " structured",
        " json",
        " django",
        " fastapi",
        " flask",
        " universal",
        " schema",
        " orjson",
        " structlog"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ab95a450c96022636fa62e63cb8a565ffad43bcde3dedc9aec50e7013f3e0738",
                "md5": "27be61beb705cbcd957d6e73c264187c",
                "sha256": "881e7019f8a5e55ed91201194442cbda4bc14468fd77d70f842eebf77e979526"
            },
            "downloads": -1,
            "filename": "json_logify-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "27be61beb705cbcd957d6e73c264187c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 10423,
            "upload_time": "2025-09-08T09:43:14",
            "upload_time_iso_8601": "2025-09-08T09:43:14.404958Z",
            "url": "https://files.pythonhosted.org/packages/ab/95/a450c96022636fa62e63cb8a565ffad43bcde3dedc9aec50e7013f3e0738/json_logify-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "76519966102ac7b45a30df1a1b9c5288c73782750912e0813caf7b62d09e12e5",
                "md5": "490884dbc97d01f395d2daa8f5b93d90",
                "sha256": "4baf23b234fc1635482ab5a7f2e13d55aac124d237442b7c1a87ed6f191a8291"
            },
            "downloads": -1,
            "filename": "json_logify-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "490884dbc97d01f395d2daa8f5b93d90",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 16260,
            "upload_time": "2025-09-08T09:43:15",
            "upload_time_iso_8601": "2025-09-08T09:43:15.771558Z",
            "url": "https://files.pythonhosted.org/packages/76/51/9966102ac7b45a30df1a1b9c5288c73782750912e0813caf7b62d09e12e5/json_logify-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-08 09:43:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yourusername",
    "github_project": "json-logify",
    "github_not_found": true,
    "lcname": "json-logify"
}
        
Elapsed time: 1.45051s