marvinlabs/laravel-discord-logger is a laravel package providing a logging handler to send logs to a Discord channel.
You can install the package via composer:
composer require marvinlabs/laravel-discord-loggerIf you are using Laravel 5.5 or later, the service provider will automatically be discovered.
On earlier versions, you need to do that manually. You must install the service provider:
// config/app.php
'providers' => [
...
MarvinLabs\DiscordLogger\ServiceProvider::class
];You can then publish the configuration file:
php artisan vendor:publish --provider "MarvinLabs\DiscordLogger\ServiceProvider"Create a discord web hook for the channel which will receive the logs.
You must add a new channel to your config/logging.php file:
// config/logging.php
'channels' => [
//...
'discord' => [
'driver' => 'custom',
'via' => MarvinLabs\DiscordLogger\Logger::class,
'level' => 'debug',
'url' => env('LOG_DISCORD_WEBHOOK_URL'),
'ignore_exceptions' => env('LOG_DISCORD_IGNORE_EXCEPTIONS', false),
],
];You can then provide the web-hook URL in your .env file:
LOG_DISCORD_WEBHOOK_URL=https://discordapp.com/api/webhooks/abcd/1234
You have two options: log only to discord or add the channel to the stack
Simply change the .env variable to use the discord channel
LOG_CHANNEL=discord
Add the channel to the stack in the config/logging.php configuration:
// config/logging.php
'channels' => [
//...
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'discord'],
],
];Then make sure the logging channel is set to stack in your .env file:
LOG_CHANNEL=stack
Of course, you can send your log messages to multiple Discord channels. Just create as many channels as desired in
config/logging.php and put them in the stack. Each channel should be named differently and should point to a different
web hook URL.
You can get a preview of what it looks like using each of the provided converters.
You might encounter this exception alongside "cURL error 60: SSL certificate problem: unable to get local issuer certificate" while using/testing your web hook in a development enviroment. This occurs due to your local machine's inability to verify the server's SSL certificate.
-
Obtain the cacert.pem file from the curl website.
-
Store the cacert.pem file in a secure location on your computer, such as C:\xampp\php\extras\ssl\cacert.pem.
-
Access your php.ini file, typically found in your PHP installation directory.
-
Locate curl.cainfo = in php.ini. If it's commented out (begins with a ;), remove the semicolon.
-
Insert the path to cacert.pem you saved earlier. Example: curl.cainfo = "C:\xampp\php\extras\ssl\cacert.pem".
-
Save the php.ini file and restart your server to implement the changes.
See the dedicated change log
- Got some ideas from GrKamil/laravel-telegram-logging
- Got some ideas from lefuturiste/monolog-discord-handler
The MIT License (MIT). Please see License File for more information.
