Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down Expand Up @@ -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": "[email protected]",
"sender_password": "yourpassword",
"recipient_emails": ["[email protected]"],
"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.
Expand Down
Loading