diff --git a/README.md b/README.md index 6c9114e..139cb29 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,23 @@ [![Python versions](https://img.shields.io/pypi/pyversions/escalite.svg)](https://pypi.org/project/escalite/) [![codecov](https://codecov.io/gh/rakibulhaq/escalite/branch/main/graph/badge.svg)](https://codecov.io/gh/rakibulhaq/escalite) [![Snyk](https://github.com/rakibulhaq/escalite/actions/workflows/snyk.yml/badge.svg?branch=main)](https://github.com/rakibulhaq/escalite/actions/workflows/snyk.yml) - +[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) +[![PyPI - Downloads](https://img.shields.io/pypi/dm/escalite.svg?label=PyPI%20downloads)](https://pypistats.org/packages/escalite) A Python library for per-request logging and escalation, designed for API services. +## Features +- Supports multiple notifiers (Email, Slack, Telegram, WhatsApp) +- Per-request logging using `contextvars` +- Unique `alert_id` generation for each log session +- Pluggable notifiers: Email, Slack, Telegram, WhatsApp and can be extended with custom notifiers +- Flexible escalation with severity filtering (`from_level`) +- Easy integration with FastAPI and other Python frameworks +- Service call lifecycle logging (`start_service_log`/`stop_service_log`) +- Context manager and manual logging support + + ## Installation **Using pip:** @@ -296,11 +308,42 @@ Escalite.end_logging() Escalite.escalate() ``` -## Features +**`Escalite.escalate()` with the `from_level` argument:** +- The `from_level` parameter controls the minimum log level required to trigger escalation (e.g., "warning", "error", "critical"). +- In this example, escalation will only occur if the log level is "error" or higher. + +Here is an example showing how to use This allows escalation to be triggered only if the log level is equal to or higher than the specified level. +```python +from escalite.escalite import Escalite + +notifier_configs = { + "notifiers": [ + { + "type": "email", + "config": { + "smtp_server": "smtp.example.com", + "smtp_port": 587, + "sender_email": "your@email.com", + "sender_password": "yourpassword", + "recipient_emails": ["admin@example.com"], + "use_tls": True + } + } + ] +} + +Escalite.set_notifiers_from_configs(notifier_configs) +Escalite.start_logging() +Escalite.add_to_log("event", "Something went wrong", tag="api_logs") +Escalite.add_service_log("my_service", "An error occurred", level="error") +Escalite.end_logging() + +# Only escalate if the log level is "error" or higher +Escalite.escalate(from_level="error") +``` + +This ensures notifications are sent only for logs at the specified severity or above. -- Per-request logging using contextvars -- Pluggable notifiers (email, etc.) -- Easy integration with FastAPI and other frameworks ## Contributing Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for guidelines.