Skip to main content

Library for logging runtime errors and sending execution reports via Telegram and Email

Project description

runreporter

Библиотека для логирования ошибок и отправки отчетов по завершению выполнения.

Возможности:

  • Логирование в файл
  • Сбор последних 300 строк лога в отчет
  • Отправка отчетов в Telegram (по chat_id)
  • Отправка отчетов на Email (SMTP)
  • Флаги: отправлять ли отчеты при отсутствии ошибок; приоритетный канал (Telegram/Email)

Установка

pip install .

Примеры использования

Вариант 1: через контекстный менеджер (with)

from runreporter import ErrorManager, SmtpConfig

manager = ErrorManager(
    log_file_path="app.log",
    telegram_bot_token="123:ABC",
    telegram_chat_ids=[11111111, 22222222],
    smtp_config=SmtpConfig(
        host="smtp.example.com",
        port=465,
        username="user@example.com",
        password="pass",
        use_ssl=True,
        from_addr="user@example.com",
    ),
    email_recipients=["dev1@example.com", "dev2@example.com"],
    send_reports_without_errors=False,
    primary_channel="telegram",  # "telegram" или "email"
)

with manager.context(run_name="Ежедневный импорт") as log:
    log.info("Начало работы")
    # ваш код
    log.error("Ошибка обработки записи id=42")

Вариант 2: без with (явный старт и финиш)

from runreporter import ErrorManager, SmtpConfig

manager = ErrorManager(
    log_file_path="app.log",
    telegram_bot_token="123:ABC",
    telegram_chat_ids=[11111111],
    smtp_config=SmtpConfig(
        host="smtp.example.com",
        port=465,
        username="user@example.com",
        password="pass",
        use_ssl=True,
    ),
    email_recipients=["dev@example.com"],
    send_reports_without_errors=False,
    primary_channel="email",
)

log = manager.get_logger(run_name="Ночной job")

try:
    log.info("Старт job")
    # ваш код
    raise RuntimeError("Пример ошибки")
except Exception:
    log.exception("Произошло исключение")
finally:
    # В конце выполнения явно инициируем отправку отчета
    manager.send_report()  # можно передать run_name вручную: manager.send_report("Ночной job")

Конфигурация

  • send_reports_without_errors: если False, отчеты будут отправляться только при наличии ошибок
  • primary_channel: "telegram" или "email" — приоритет канала; второй используется как резервный

Лицензия

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

runreporter-0.2.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

runreporter-0.2.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file runreporter-0.2.0.tar.gz.

File metadata

  • Download URL: runreporter-0.2.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for runreporter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bc4dba770d9eba2e7c90bb2f72d4c1b152bf8c0066f6780f609fb1bb078790ec
MD5 390e4f0cc9267404e740e861d7bd96c4
BLAKE2b-256 30c860cf270c0b83c569b8f357a3304d139eeed2d0bc72cc81c2b9572beb084c

See more details on using hashes here.

File details

Details for the file runreporter-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: runreporter-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for runreporter-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4753873d78aaecddefbc8914126bbdcfb18f6207e4186e553de4edefca015e40
MD5 002abba2c1f0b2632ce400bfcf18ec1d
BLAKE2b-256 c321438d7ee2fbdbcc8017cfba7514d64669be65eb1925e122177bb817140aad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page