|
2 | 2 |
|
3 | 3 | namespace KABBOUCHI\LoggerDiscordChannel; |
4 | 4 |
|
| 5 | +use GuzzleHttp\Exception\GuzzleException; |
| 6 | +use GuzzleHttp\RequestOptions; |
5 | 7 | use Monolog\Formatter\LineFormatter; |
6 | 8 | use \Monolog\Logger; |
7 | 9 | use \Monolog\Handler\AbstractProcessingHandler; |
@@ -41,14 +43,27 @@ protected function write(array $record) |
41 | 43 | { |
42 | 44 | $formatter = new LineFormatter(null, null, true, true); |
43 | 45 | $formatter->includeStacktraces(); |
44 | | - |
45 | 46 | $content = $formatter->format($record); |
46 | 47 |
|
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, |
52 | 67 | ]); |
53 | 68 | } |
54 | 69 | } |
0 commit comments