Skip to content

Commit 67d1979

Browse files
author
MegaXLR
committed
Change message format to embed
Signed-off-by: MegaXLR <[email protected]>
1 parent 5083942 commit 67d1979

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/DiscordHandler.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace KABBOUCHI\LoggerDiscordChannel;
44

5+
use GuzzleHttp\Exception\GuzzleException;
6+
use GuzzleHttp\RequestOptions;
57
use Monolog\Formatter\LineFormatter;
68
use \Monolog\Logger;
79
use \Monolog\Handler\AbstractProcessingHandler;
@@ -41,14 +43,27 @@ protected function write(array $record)
4143
{
4244
$formatter = new LineFormatter(null, null, true, true);
4345
$formatter->includeStacktraces();
44-
4546
$content = $formatter->format($record);
4647

47-
48-
$this->guzzle->request('POST', $this->webhook, [
49-
'form_params' => [
50-
'content' => env('APP_URL') . " on fire 🔥 \n\n" . substr($content, 0, 1900)
51-
]
48+
// Set up the formatted log
49+
$log = [
50+
'embeds' => [
51+
[
52+
'title' => 'Log from ' . $this->name,
53+
// Use CSS for the formatter, as it provides the most distinct colouring.
54+
'description' => "```css\n" . substr($content, 0, 2030). '```',
55+
'color' => 0xE74C3C,
56+
],
57+
],
58+
];
59+
60+
// Tag a role if configured for it
61+
if(config('logging.discord.role_id')) $log['content'] = "<@&" . config('logging.discord.role_id') . ">";
62+
63+
64+
// Send it to discord
65+
$this->guzzle->request('POST', $this->webhook, [
66+
RequestOptions::JSON => $log,
5267
]);
5368
}
5469
}

0 commit comments

Comments
 (0)