logger_webhook_h
=====
This is an [OTP logger handler](https://erlang.org/doc/apps/kernel/logger_chapter.html#handlers) for Erlang that sends a Webhook message for log events.
It uses multipart/form-data, so make sure the receiver supports this.
It's been tested to work fine with Discord.
Usage
-----
Shell example:
```
logger:add_handler(error_webhook, logger_webhook_h, #{
config => #{ url => "https://discord.com/api/webhooks/023916370468945/jWxqZRTNWiP9qejPG6-P-z_UG3IVM_7nVt5nWSoir8bEsIV9iWXgIkNcLiBohTFSW" },
level => warning,
formatter => {logger_formatter, #{ single_line => false }}
}).
```
sys.config example:
```
[
{kernel, [
{logger, [
{handler, error_webhook, logger_webhook_h,
#{ config => #{ url => "https://discord.com/api/webhooks/12345/chyschmancyid" },
level => warning,
formatter => {logger_formatter, #{ single_line => false }}}}
]}
]}
].
```
How it looks:
```
11> logger:debug("this one won't be sent").
=DEBUG REPORT==== 14-Aug-2021::11:52:29.217000 ===
this one won't be sent
ok
12> logger:warning("but this one needs to be known!").
=WARNING REPORT==== 14-Aug-2021::11:52:40.114000 ===
but this one needs to be known!
ok
13> logger:warning("There's been a complicated error: ~p", [{#Ref<0.2049192390.542638081.248283>,{http_error,500,#{<<"error">> => <<"Internal Server Error">>,<<"message">> => <<>>,<<"status">> => 500}}}]).
=WARNING REPORT==== 14-Aug-2021::11:53:52.840000 ===
There's been a complicated error: {#Ref<0.2049192390.542638081.248283>,
{http_error,500,
#{<<"error">> =>
<<"Internal Server Error">>,
<<"message">> => <<>>,
<<"status">> => 500}}}
ok
```
![screenshot from discord](screenshot.jpg)
Caveats
-------
Logging will fail silently if httpc and inets aren't started. This is intentional as alternative behaviors are worse.
The handler will intentionally fail if a non-success response is received when sending the webhook message.