LoggerTelegramBackend

A logger backend for Telegram.

Installation

Add :logger_telegram_backend to your list of dependencies in mix.exs:

def deps do
[{:logger_telegram_backend, "~> 1.2"}]
end

Configuration

First of all you need to create a Telegram bot. Follow the instructions here to create one and get the token for the bot. Since bots are not allowed to contact users, you need to send a message first. Afterwards, retrieve your chat_id with $ curl -X GET https://api.telegram.org/botYOUR_TOKEN/getUpdates.

Then add LoggerTelegramBackend to the :backends configuration, configure the telegram chat_id and bot token:

config :logger, backends: [LoggerTelegramBackend, :console]
config :logger, :telegram,
chat_id: "$chatId",
token: "$botToken"

The logger configuration is read at runtime from the application environment so that you can provide it via distillerys dynamic configuration with environment variables.

Options

The following options are available:

Examples

With Metadata Filter
config :logger, :telegram,
chat_id: "$chatId",
token: "$botToken",
level: :info,
metadata: :all
metadata_filter: [application: :ui]
With Proxy
config :logger, :telegram,
chat_id: "$chatId",
token: "$botToken",
proxy: "socks5://127.0.0.1:9050"

Multiple logger handlers

Like the LoggerFileBackend multiple logger handlers may be configured, each with different :chat_ids, :levels etc. Each handler has to be configured as a separate logger backend:

config :logger,
backends: [
{LoggerTelegramBackend, :telegram_filter},
{LoggerTelegramBackend, :telegram_level},
:console
]
config :logger, :telegram_filter,
chat_id: "$chatId",
token: "$botToken",
metadata_filter: [application: :ui],
metadata: [:line, :function, :module, :pid]
config :logger, :telegram_level,
chat_id: "$chatId",
token: "$botToken",
level: :warn