Skip to content

Instantly share code, notes, and snippets.

@danielstgt
Last active January 7, 2025 11:48
Show Gist options
  • Save danielstgt/46b79532ec50273cb626f6c6414284c9 to your computer and use it in GitHub Desktop.
Save danielstgt/46b79532ec50273cb626f6c6414284c9 to your computer and use it in GitHub Desktop.
Use Discord for Laravel Error Logging without 3rd party packages

Migration Guide

1) Get the webhook URL for your channel on Discord

Click on the channel settings icon and select integrations.

2) Create a new entry in your .env

LOG_DISCORD_WEBHOOK_URL=<insert-the-webhook-url-here>

3) Edit the config/logging.php file

use Monolog\Handler\SlackWebhookHandler;

// ...

// place this inside the channels array
'discord' => [
    'driver'       => 'monolog',
    'level'        => env('LOG_LEVEL', 'error'),
    'handler'      => SlackWebhookHandler::class,
    'handler_with' => [
        'webhookUrl'             => env('LOG_DISCORD_WEBHOOK_URL') . '/slack',
        'username'               => env('APP_NAME') . ' (' . env('APP_ENV') . ')',
        'includeContextAndExtra' => true,
        'useAttachment'          => true,
        'useShortAttachment'     => true,
    ],
],

4) Adjust your error reporting channel. Example for stack

'stack' => [
    'driver'            => 'stack',
    'channels'          => 'daily,discord',
    'ignore_exceptions' => false,
],

5) Done! Have a nice day.

Additional Info

The error logging config appends a /slack to the URL to make the logging compatible.

Don't forget to append /slack to your discord webhook URLs ff you need a slack compatible webhook for something else than logging.

Error Logging Discord Webhook URL

https://discord.com/api/webhooks/<whatever>/<whatever>

Slack Compatible Discord Webhook URL for other things

https://discord.com/api/webhooks/<whatever>/<whatever>/slack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment