pylogalert


Namepylogalert JSON
Version 0.1.6.1 PyPI version JSON
download
home_pageNone
SummaryLean JSON logging with async-safe context, PII redaction, sampling, and EMERGENCY alerts.
upload_time2025-08-30 03:04:53
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords django fastapi json logging observability
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pylogalert

**Lean JSON logging** for Python with **async-safe contextvars**, **PII redaction**, **sampling**, and **EMERGENCY alerts** (Slack, SES).  
Designed for production services and framework integration (FastAPI, Django).

---

## 🚀 Installation

```bash
pip install pylogalert
# optional extras
pip install pylogalert[ses]   # enable AWS SES email notifications
```

## 🔑 Features

- Structured JSON logs (NDJSON, one log per line).

- Context propagation: async-safe via contextvars.

- PII Redaction: hide sensitive keys or regex patterns.

- Sampling: reduce noise and cost (info: 0.1, debug: 0.01).

- New log level: EMERGENCY (≥ CRITICAL).

- Exception logging: automatic exc_type, exc_message, and stack.

- Notifications: plugable notifier system with:

- Slack Webhook (built-in)

- AWS SES email (optional extra [ses])

- Rate limiting, deduplication, retries

- Framework integration: ready to plug into FastAPI middleware or Django logging config.

- Zero mandatory deps (stdlib only).

## 📖 Usage

### Basic logging
```bash
import pylogalert as log

log.configure(service="checkout-api", env="prod")

log.set_context(request_id="req-123")
log.info("order_created", user_id=42, order_id=777, value=129.9)

try:
    1/0
except:
    log.exception("unexpected_error", user_id=42, order_id=777)

```

Output (colorized if LOG_PRETTY=1 or stream.isatty()):

```bash
{"ts":"2025-08-29T12:00:00Z","level":"INFO","service":"checkout-api","env":"prod","event":"order_created","request_id":"req-123","user_id":42,"order_id":777,"value":129.9}
{"ts":"2025-08-29T12:00:00Z","level":"ERROR","service":"checkout-api","env":"prod","event":"unexpected_error","request_id":"req-123","user_id":42,"order_id":777,"exc_type":"ZeroDivisionError","exc_message":"division by zero","stack":"Traceback ..."}

```

### PII redaction
```bash
log.configure(service="auth", env="prod",
              redact_keys=["password", "token"],
              redact_regexes=[r"\b\d{3}\.\d{3}\.\d{3}\-\d{2}\b"])  # hide CPF

log.info("user_login", email="a@x.com", password="secret123")
````
Output:
```bash
{"event":"user_login","email":"a@x.com","password":"***REDACTED***"}
```

### Emergency alerts (Slack)
```bash
import pylogalert as log
from pylogalert.notify import Notifier
from pylogalert.notify_slack import slack_webhook

slack = slack_webhook("https://hooks.slack.com/services/XXX/YYY/ZZZ")

notifier = Notifier(
    channels=[slack],
    rate_limit=("6/min", 5),
    dedupe_window=60,
    retries=(2, 2.0),
)

log.configure(service="billing", env="prod")
log.emergency("payment_failed", invoice="inv-001", amount=199.0, _notify=notifier)
````

### Emergency alerts (AWS SES)

```bash
import pylogalert as log
from pylogalert.notify import Notifier
from pylogalert.notify_ses import ses_email  # requires: pip install pylogalert[ses]

notifier = Notifier(
    channels=[ses_email(sender="alerts@mydomain.com", to=["ops@mydomain.com"])],
    rate_limit=("1/min", 1),
)

log.configure(service="checkout", env="prod")
log.emergency("critical_invariant_broken", account_id=123, _notify=notifier)
````

## ⚙️ Environment variables
- LOG_LEVEL: default log level (default: INFO)

- APP_ENV: environment tag (default: dev)

- LOG_PRETTY: enable colors (1, true, yes)

## 📦 Project status

- 0.1.0 – first release

- Semantic Versioning (SemVer)

- MIT licensed

## 🛠 Development
```bash
git clone https://github.com/jonrato/pylogalert.git
cd pylogalert
python3 -m venv venv && source venv/bin/activate
pip install -e ".[all]"   # install with extras
pytest -q
```
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pylogalert",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "django, fastapi, json, logging, observability",
    "author": null,
    "author_email": "Jonatas Ferreira Viana Silva <jonatas_ferreira@usp.br>",
    "download_url": "https://files.pythonhosted.org/packages/b6/c3/704beb1a679aa0cdc215e3f6f82c7df3109bc98758a898486c0e90e2eb13/pylogalert-0.1.6.1.tar.gz",
    "platform": null,
    "description": "# pylogalert\n\n**Lean JSON logging** for Python with **async-safe contextvars**, **PII redaction**, **sampling**, and **EMERGENCY alerts** (Slack, SES).  \nDesigned for production services and framework integration (FastAPI, Django).\n\n---\n\n## \ud83d\ude80 Installation\n\n```bash\npip install pylogalert\n# optional extras\npip install pylogalert[ses]   # enable AWS SES email notifications\n```\n\n## \ud83d\udd11 Features\n\n- Structured JSON logs (NDJSON, one log per line).\n\n- Context propagation: async-safe via contextvars.\n\n- PII Redaction: hide sensitive keys or regex patterns.\n\n- Sampling: reduce noise and cost (info: 0.1, debug: 0.01).\n\n- New log level: EMERGENCY (\u2265 CRITICAL).\n\n- Exception logging: automatic exc_type, exc_message, and stack.\n\n- Notifications: plugable notifier system with:\n\n- Slack Webhook (built-in)\n\n- AWS SES email (optional extra [ses])\n\n- Rate limiting, deduplication, retries\n\n- Framework integration: ready to plug into FastAPI middleware or Django logging config.\n\n- Zero mandatory deps (stdlib only).\n\n## \ud83d\udcd6 Usage\n\n### Basic logging\n```bash\nimport pylogalert as log\n\nlog.configure(service=\"checkout-api\", env=\"prod\")\n\nlog.set_context(request_id=\"req-123\")\nlog.info(\"order_created\", user_id=42, order_id=777, value=129.9)\n\ntry:\n    1/0\nexcept:\n    log.exception(\"unexpected_error\", user_id=42, order_id=777)\n\n```\n\nOutput (colorized if LOG_PRETTY=1 or stream.isatty()):\n\n```bash\n{\"ts\":\"2025-08-29T12:00:00Z\",\"level\":\"INFO\",\"service\":\"checkout-api\",\"env\":\"prod\",\"event\":\"order_created\",\"request_id\":\"req-123\",\"user_id\":42,\"order_id\":777,\"value\":129.9}\n{\"ts\":\"2025-08-29T12:00:00Z\",\"level\":\"ERROR\",\"service\":\"checkout-api\",\"env\":\"prod\",\"event\":\"unexpected_error\",\"request_id\":\"req-123\",\"user_id\":42,\"order_id\":777,\"exc_type\":\"ZeroDivisionError\",\"exc_message\":\"division by zero\",\"stack\":\"Traceback ...\"}\n\n```\n\n### PII redaction\n```bash\nlog.configure(service=\"auth\", env=\"prod\",\n              redact_keys=[\"password\", \"token\"],\n              redact_regexes=[r\"\\b\\d{3}\\.\\d{3}\\.\\d{3}\\-\\d{2}\\b\"])  # hide CPF\n\nlog.info(\"user_login\", email=\"a@x.com\", password=\"secret123\")\n````\nOutput:\n```bash\n{\"event\":\"user_login\",\"email\":\"a@x.com\",\"password\":\"***REDACTED***\"}\n```\n\n### Emergency alerts (Slack)\n```bash\nimport pylogalert as log\nfrom pylogalert.notify import Notifier\nfrom pylogalert.notify_slack import slack_webhook\n\nslack = slack_webhook(\"https://hooks.slack.com/services/XXX/YYY/ZZZ\")\n\nnotifier = Notifier(\n    channels=[slack],\n    rate_limit=(\"6/min\", 5),\n    dedupe_window=60,\n    retries=(2, 2.0),\n)\n\nlog.configure(service=\"billing\", env=\"prod\")\nlog.emergency(\"payment_failed\", invoice=\"inv-001\", amount=199.0, _notify=notifier)\n````\n\n### Emergency alerts (AWS SES)\n\n```bash\nimport pylogalert as log\nfrom pylogalert.notify import Notifier\nfrom pylogalert.notify_ses import ses_email  # requires: pip install pylogalert[ses]\n\nnotifier = Notifier(\n    channels=[ses_email(sender=\"alerts@mydomain.com\", to=[\"ops@mydomain.com\"])],\n    rate_limit=(\"1/min\", 1),\n)\n\nlog.configure(service=\"checkout\", env=\"prod\")\nlog.emergency(\"critical_invariant_broken\", account_id=123, _notify=notifier)\n````\n\n## \u2699\ufe0f Environment variables\n- LOG_LEVEL: default log level (default: INFO)\n\n- APP_ENV: environment tag (default: dev)\n\n- LOG_PRETTY: enable colors (1, true, yes)\n\n## \ud83d\udce6 Project status\n\n- 0.1.0 \u2013 first release\n\n- Semantic Versioning (SemVer)\n\n- MIT licensed\n\n## \ud83d\udee0 Development\n```bash\ngit clone https://github.com/jonrato/pylogalert.git\ncd pylogalert\npython3 -m venv venv && source venv/bin/activate\npip install -e \".[all]\"   # install with extras\npytest -q\n```",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Lean JSON logging with async-safe context, PII redaction, sampling, and EMERGENCY alerts.",
    "version": "0.1.6.1",
    "project_urls": {
        "Homepage": "https://github.com/jonrato/pylogalert",
        "Issues": "https://github.com/jonrato/pylogalert/issues"
    },
    "split_keywords": [
        "django",
        " fastapi",
        " json",
        " logging",
        " observability"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5b807eb1e1cab4ae27e4d7eedd6ff834ac7e770b18ef373dafe16d8fa1b8fe3e",
                "md5": "59907468f4f301476bf6c2b394082a06",
                "sha256": "744bf139223f913f104fe7d9d717d8cf221eb53350f2bc92e2165179daecf875"
            },
            "downloads": -1,
            "filename": "pylogalert-0.1.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "59907468f4f301476bf6c2b394082a06",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9593,
            "upload_time": "2025-08-30T03:04:52",
            "upload_time_iso_8601": "2025-08-30T03:04:52.177551Z",
            "url": "https://files.pythonhosted.org/packages/5b/80/7eb1e1cab4ae27e4d7eedd6ff834ac7e770b18ef373dafe16d8fa1b8fe3e/pylogalert-0.1.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b6c3704beb1a679aa0cdc215e3f6f82c7df3109bc98758a898486c0e90e2eb13",
                "md5": "afcee6dc939f704760270ad345e4c74a",
                "sha256": "ef9d9ad5efa327fe5b5d89c70bb619006343b39155fefed15464db00c45ebf78"
            },
            "downloads": -1,
            "filename": "pylogalert-0.1.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "afcee6dc939f704760270ad345e4c74a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 9683,
            "upload_time": "2025-08-30T03:04:53",
            "upload_time_iso_8601": "2025-08-30T03:04:53.493698Z",
            "url": "https://files.pythonhosted.org/packages/b6/c3/704beb1a679aa0cdc215e3f6f82c7df3109bc98758a898486c0e90e2eb13/pylogalert-0.1.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-30 03:04:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jonrato",
    "github_project": "pylogalert",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pylogalert"
}
        
Elapsed time: 0.81135s