Skip to main content

Logging handlers to send logs to discord and telegram

Project description

Logcaster

A package to send loggings to discord, telegram and whatever other location with the proposal of easily implements observability to small and lower coast applications

🛠🔧 Project in development process 🔧🛠

Available sources

  • Discord
  • Telegram

Features

  • easy to use.
  • natively supported by the built-in python logging package.
  • async support.

Quick-start

Requirements

Install

# by defaults supports telegram setup
poetry add logcaster

# discord
poetry add "logcaster[discord]"

Configure

Once installed, you need only set the environment vars (see: .env example file)

# .env
TELEGRAM__BOT_TOKEN=<you bot token>
TELEGRAM__CHAT_ID=<the chat id which the bot will send logs>

Usage

import logging
from logcaster.telegram import TelegramHandler, TelegramFormatter

logger = logger.getLogger('my-application-logger')

handler = TelegramHandler()
formatter = TelegramFormatter(include_fields=['message', 'asctime'])

handler.setFormatter(formatter)
logger.addLogger(logger)

Note: The default level is setting up to ERROR, it's highly recommended don't set a lower level, cause each emitted logging will make a request to the given source.

Django example

# settings.py
LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "telegram_fmt": {
            "class": "logcaster.telegram.TelegramFormatter",
        },
        "discord_fmt": {
            "class": "logcaster.discord.DiscordFormatter",
            "exclude_fields": ['funcName', 'lineno'],
        }
    },
    "handlers": {
        "telegram": {
            "class": "logcaster.telegram.TelegramHandler",
        },
        "discord": {
            "class": "logcaster.discord.DiscordHandler",
            "exclude_fields": ['funcName', 'lineno'],
        }
    },
    "loggers": {
        "logcaster": {
            "handlers": ["telegram", "discord"],
            "formatters": ["telegram_fmt", "discord_fmt"],
            "level": "ERROR",
            "propagate": False,
        },
    },
}

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

logcaster-0.1.3.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

logcaster-0.1.3-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file logcaster-0.1.3.tar.gz.

File metadata

  • Download URL: logcaster-0.1.3.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.10.11 Windows/10

File hashes

Hashes for logcaster-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2cb7a09bcfb6f7009a9d4f7cfef24e0ac8f4df9b0c435c87a18e9f69ccd57f28
MD5 401efa300358109a3818ec4281e778c8
BLAKE2b-256 3345d30b3b024dfdb190db52a1d91ca9d749d444b06c905ec049cd6e47283afc

See more details on using hashes here.

File details

Details for the file logcaster-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: logcaster-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.10.11 Windows/10

File hashes

Hashes for logcaster-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ec757b3b5ab4fa588e3ce68f22e4cf4f9a56ecb277a12ebe933577250dd6e786
MD5 0c6ca63f65b5e7ae00628637bbbec153
BLAKE2b-256 75412b82be1785de6b6483396060a46036ec8f3aca1b1d7b86fe8934a915eec4

See more details on using hashes here.

Supported by

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