LoggerTelegramBackend

Build StatusDocsHex.pm

A logger backend for Telegram.

Installation

Add :logger_telegram_backend, :logger_backends and :finch to your list of dependencies in mix.exs:

def deps do
[
{:logger_telegram_backend, "~> 3.0-rc"},
{:logger_backends, "~> 1.0"},
{:finch, "~> 1.18"},
]
end

In your Application.start/2 callback, add the LoggerTelegramBackend backend:

@impl true
def start(_type, _args) do
LoggerBackends.add(LoggerTelegramBackend)
# ...
end

Configuration

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

Then configure the telegram chat_id and bot token:

config :logger, LoggerTelegramBackend,
chat_id: "$chatId",
token: "$botToken"

Options

The available options are:

Examples

Custom HTTP client

  1. Add a module that implements the LoggerTelegramBackend.HTTPClient behaviour

  2. Pass your client module to the :client option:

    config :logger, LoggerTelegramBackend,
    client: MyClient,
    # ...

Metadata filter

config :logger, LoggerTelegramBackend,
chat_id: "$chatId",
token: "$botToken",
level: :info,
metadata: :all,
metadata_filter: [application: :ui]

SOCKS5 proxy

config :logger, LoggerTelegramBackend,
chat_id: "$chatId",
token: "$botToken",
client: LoggerTelegramBackend.HTTPClient.Hackney,
client_request_opts: [
proxy: {:socks5, ~c"127.0.0.1", 9050}
]

See the hackney docs for further information.