diff --git a/README.md b/README.md index d26c379..29fe531 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,7 @@ defp deps do {:image, "~> 0.55"}, {:jason, "~> 1.4"}, {:plug_cowboy, "~> 2.7"}, - {:quantum, "~> 3.5"}, - {:tesla, "~> 1.13"} + {:quantum, "~> 3.5"} ] end ``` diff --git a/lib/logger/discord_logger.ex b/lib/logger/discord_logger.ex index d153895..df34154 100644 --- a/lib/logger/discord_logger.ex +++ b/lib/logger/discord_logger.ex @@ -1,8 +1,5 @@ defmodule PlantIdDiscordBot.DiscordLogger do require Logger - use Tesla - - plug(Tesla.Middleware.JSON) @behaviour :gen_event @@ -40,13 +37,26 @@ defmodule PlantIdDiscordBot.DiscordLogger do def log_to_discord(webhook_url, level, msg, ts, md) do formatted_msg = format_message(level, msg, ts, md) - body = %{content: formatted_msg} + body = %{content: formatted_msg} |> Jason.encode!() + headers = [{~c"Content-Type", ~c"application/json"}] - post(webhook_url, body) + :httpc.request( + :post, + {webhook_url, headers, ~c"application/json", body}, + [], + [] + ) |> case do - {:ok, %{status: status}} when status in 200..299 -> :ok - {:error, reason} -> Logger.error("Error sending log to Discord: #{inspect(reason)}") - _any -> Logger.error("Error sending log to Discord") + {:ok, {{~c"HTTP/1.1", status, _}, _headers, _body}} when status in 200..299 -> + :ok + + {:ok, {{~c"HTTP/1.1", status, _}, _headers, response_body}} -> + Logger.error( + "Failed to send log to Discord: Status #{status}, Body: #{inspect(response_body)}" + ) + + {:error, reason} -> + Logger.error("Error sending log to Discord: #{inspect(reason)}") end end diff --git a/mix.exs b/mix.exs index 24d0bc8..2f5d011 100644 --- a/mix.exs +++ b/mix.exs @@ -14,7 +14,7 @@ defmodule PlantidDiscordBot.MixProject do # Run "mix help compile.app" to learn about applications. def application do [ - extra_applications: [:logger], + extra_applications: [:logger, :observer, :wx, :runtime_tools], mod: {PlantIdDiscordBot.Application, []} ] end @@ -28,8 +28,7 @@ defmodule PlantidDiscordBot.MixProject do {:image, "~> 0.55"}, {:jason, "~> 1.4"}, {:plug_cowboy, "~> 2.7"}, - {:quantum, "~> 3.5"}, - {:tesla, "~> 1.13"} + {:quantum, "~> 3.5"} ] end end