Skip to content

Commit 9f8468a

Browse files
authored
Merge pull request #1 from megaxlr/master
Embed errors and tagging
2 parents 5083942 + 0013295 commit 9f8468a

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ Add the new driver type in your `config/logging.php` configuration
2121
],
2222
],
2323

24+
// role to tag in the error
25+
'discord' => [
26+
'role_id' => '',
27+
],
2428
```

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)