Metadata-Version: 2.4
Name: rse-logging
Version: 0.1.6
Summary: RSE standard logging with correlation id, Vault-backed Telegram alerts, and FastAPI middleware.
Author: RSE Team
Requires-Python: >=3.12,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Dist: fastapi (>=0.115.0,<0.116.0)
Requires-Dist: httpx (>=0.27.0,<0.28.0)
Requires-Dist: hvac (>=2.4.0,<3.0.0)
Description-Content-Type: text/markdown

# rse-logging

RSE standard logging package for Python APIs.

Features:

- colored console logs
- request correlation id with `ContextVar`
- FastAPI middleware for `X-Correlation-ID`
- helper functions: `log_info`, `log_warning`, `log_error`
- Telegram alerts for `ERROR` logs in `stg` and `prd`
- Telegram credentials loaded from HashiCorp Vault

## Usage

```python
from fastapi import FastAPI
from rse_logging import CorrelationIdMiddleware, log_error, setup_logger

setup_logger("my-api")

app = FastAPI()
app.add_middleware(CorrelationIdMiddleware)

log_error("startup", "Example error")
```

## Diagnostics

To debug Telegram/Vault configuration without printing tokens:

```python
from rse_logging import diagnose_telegram, setup_logger

setup_logger("my-api")
print(diagnose_telegram(send_test_message=True))
```

Set `RSE_LOGGING_DEBUG=true` to print skipped Telegram alert reasons to stderr.

## Vault

Telegram alerts are enabled only when `RSE_ENV` is `stg` or `prd`.

The package reads Vault using:

- `RSE_ENV` as the KV v2 mount point
- `RSE_VAULT_HOST` as the Vault URL
- `RSE_VAULT_TOKEN` as the Vault token
- `shared` as the default secret path

Expected keys:

```text
telegram_bot_token
telegram_chat_id
```

Examples:

```text
stg/shared.telegram_bot_token
stg/shared.telegram_chat_id
prd/shared.telegram_bot_token
prd/shared.telegram_chat_id
```

Set `RSE_LOGGING_TELEGRAM_ENABLED=false` to disable Telegram alerts.

