mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-23 04:26:57 +00:00
remove tesla from logger
This commit is contained in:
@@ -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
|
||||
```
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user