GithubHelp home page GithubHelp logo

adriankumpf / logger-telegram-backend Goto Github PK

View Code? Open in Web Editor NEW
24.0 5.0 4.0 196 KB

A logger backend for Telegram

Home Page: https://hex.pm/packages/logger_telegram_backend

License: MIT License

Elixir 100.00%
elixir telegram logging logger-backend telegram-bot-api

logger-telegram-backend's Introduction

LoggerTelegramBackend

Build Status Docs Hex.pm

A logger backend for Telegram.

Installation

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

def deps do
  [
    {:logger_telegram_backend, "~> 3.0"},
    {:finch, "~> 0.16"},
  ]
end

Add the backend

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

@impl true
def start(_type, _args) do
  LoggerTelegramBackend.attach()

  # ...
end

Add the following to your configuration:

config :logger, LoggerTelegramBackend,
  chat_id: "your_chat_id",
  token: "yout_bot_token"

To create a Telegram bot, see the next section.

Configure the Telegram bot

To create a Telegram bot, follow the instructions here and get the token for the bot.

Then send a message to the bot and get your chat_id:

TOKEN="your_bot_token"
curl https://api.telegram.org/bot$TOKEN/getUpdates

License

This project is Licensed under the MIT License.

logger-telegram-backend's People

Contributors

adriankumpf avatar dependabot-preview[bot] avatar dependabot[bot] avatar mvalitov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

logger-telegram-backend's Issues

Logging not working when using a remote console

I'm a bit puzzled about this: if I release an app with mix distillery.release and start it with _build/dev/rel/testapp/bin/testapp console, Logger.error("test") will correctly result in the bot sending a message. If I connect to the very same app by _build/dev/rel/testapp/bin/testapp remote_console, Logger.error("test") will result in an error:

[error] GenServer #PID<0.107.0> terminating
** (stop) {:EXIT, {{:badmatch, {:error, %Mint.TransportError{reason: :ssl_not_started}}}, [{LoggerTelegramBackend, :handle_event, 2, [file: 'lib/telegram_logger_backend.ex', line: 47]}, {:gen_event, :server_update, 4, [file: 'gen_event.erl', line: 577]}, {:gen_event, :server_notify, 4, [file: 'gen_event.erl', line: 559]}, {:gen_event, :handle_msg, 6, [file: 'gen_event.erl', line: 300]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}}
Last message: {:gen_event_EXIT, LoggerTelegramBackend, {:EXIT, {{:badmatch, {:error, %Mint.TransportError{reason: :ssl_not_started}}}, [{LoggerTelegramBackend, :handle_event, 2, [file: 'lib/telegram_logger_backend.ex', line: 47]}, {:gen_event, :server_update, 4, [file: 'gen_event.erl', line: 577]}, {:gen_event, :server_notify, 4, [file: 'gen_event.erl', line: 559]}, {:gen_event, :handle_msg, 6, [file: 'gen_event.erl', line: 300]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}}}

I tried to add :ssl to the extra_applications, to no avail. What could be the cause of such a behavior?

I attached a minimal app to test, just mix distillery.release and run it as I explained above

testapp 2.zip

Thanks!

unknown registry?

I think I need a little help with the configuration:

In config.ex, I have:

adapter: {Tesla.Adapter.Finch, name: LoggerTelegramBackend.Finch}

in application.ex:

{Finch, name: LoggerTelegramBackend.Finch} is one of the children

but when I start the app, I get:

[error] :gen_event handler LoggerTelegramBackend installed in Logger terminating
** (ArgumentError) unknown registry: LoggerTelegramBackend.Finch

what am I missing?

Thanks!

Avoid [error] GenServer terminating

In lib/telegram_logger_backend.ex:47 the match :ok = log_event(level, message, timestamp, metadata, state) can end up in the GenServer terminating in case the returned value is, for example, {:error, reason} instead of :ok, which is not necessarily bad, if I understand well how Mint works (also see elixir-mint/mint#211). Would it make sense to ignore the returned value?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.