Send Laravel errors to Slack without flooding the channel

Laravel's Slack log channel posts every error as its own message. Get one Slack alert per spike instead, with the log lines that caused it.

Beginner10 min to complete6 min read

Before you start

  • A Laravel application
  • A Tailcove account with a source
  • A Slack workspace where you can add an app

Laravel can send errors to Slack on its own: point the built-in slack log channel at an incoming webhook and every line at its level becomes a Slack message. That's fine for the odd critical error. On a bad deploy, one broken query posts a message per request and the channel gets muted. This guide sends your logs to Tailcove instead, and an alert posts to Slack once when errors cross a threshold, with the newest matching lines in the message, and once more when they stop.

On this page8 sections

What Laravel's Slack channel does#

A new Laravel app already has the channel in config/logging.php:

'slack' => [
    'driver' => 'slack',
    'url' => env('LOG_SLACK_WEBHOOK_URL'),
    'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'),
    'emoji' => env('LOG_SLACK_EMOJI', ':boom:'),
    'level' => env('LOG_LEVEL', 'critical'),
    'replace_placeholders' => true,
],

Add slack to LOG_STACK, set LOG_SLACK_WEBHOOK_URL and it works. Before you rely on it, know how it behaves:

  • The level comes from LOG_LEVEL, the same variable your other channels read, and a new app's .env sets it to debug. Add the channel to the stack without changing that and Slack gets your debug lines. Give the channel its own level, for example 'level' => 'critical'.
  • Every line is its own HTTP call to Slack. Monolog's Slack handler makes it while the request or job that logged the line is still running, with no timeout set and retries on network errors, so a slow Slack means a slow request.
  • Nothing is grouped. If the same exception is thrown on every request, Slack gets one message per request.
  • There's no all-clear. You hear that something started, never that it stopped.

For a side project with a few critical errors a month, that can be enough. Once the app has real traffic, an alert is easier to live with.

1. Send your logs to Tailcove#

Install the package:

composer require tailcove/laravel

Add the tailcove channel to config/logging.php:

'tailcove' => [
    'driver' => 'tailcove',
    'level' => env('LOG_LEVEL', 'debug'),
],

Then put your source's ingest token in .env and add the channel to the stack:

TAILCOVE_TOKEN=your-source-ingest-token
LOG_STACK=single,tailcove

If slack was in LOG_STACK, take it out now, or every error reaches Slack twice.

The package keeps lines in memory and sends them in batches after the response has gone out, so the request that logged an error never waits on the network. The Laravel logging guide covers the rest of the setup, including exceptions and queue workers.

2. Create the alert#

Open the source in Tailcove, go to its Alerts tab and create an alert. The Error spike template is a good start: it fills in the query and a threshold of 20 lines in 5 minutes.

Field Value Why
Query level:error Every Log::error() call and every exception Laravel reports
Threshold 20 One stray error doesn't post; a real spike does
Window 5 minutes How far back each check counts
Cooldown 30 minutes The shortest gap between two firings, so a flapping alert stays quiet

Laravel reports an unhandled exception at the error level, so level:error catches those and your own Log::error() calls. A line logged with Log::critical() has its own level; use level:error OR level:critical to catch both. If you only care about exceptions, exception:* matches the lines that carry one.

On the When it fires step, Tailcove replays the alert over the source's last 7 days and shows how many times it would have fired. If the answer is 40, raise the threshold now, not after the team has learned to ignore it. A brand new source has nothing to replay yet, so come back to this after a few days of traffic.

3. Send it to Slack#

On the Who to tell step, click + Slack, then Add to Slack. Slack asks which channel to post in. Pick one and the window closes with that channel on the form. Save the alert.

Each alert posts to its own channel, so payment errors can go to #payments while everything else goes to #alerts.

When the alert fires, Slack gets one message with the alert's name and source, its condition (level:error ≥ 20 in 5 min), how many lines matched, a link to the alert, and up to five of the newest matching lines with their time and level. You can usually see the error without opening Tailcove. When the count drops back under the threshold, a second message says it resolved.

4. Test it#

Set the threshold to 1 for a moment and log an error from the app:

php artisan tinker --execute 'Log::error("Testing the Slack alert");'

Alerts are checked once a minute, so the message reaches Slack within a minute or two. Then set the threshold back. The test counts as a firing, so the cooldown applies to it like any other.

Keeping it quiet#

One alert per kind of problem tells you more than one alert for everything. level:error on the web app and a separate alert on "Queued job failed" for the workers (see failed queue jobs) say straight away which side broke.

An alert that fires often and nobody acts on needs a higher threshold or a narrower query. level:error -host:canary, for example, leaves out a canary server.

And the same exception thrown a thousand times is one issue with a count, which is a better place to work through errors than a Slack channel.

FAQ#

How do I send Laravel errors to Slack?

There are two ways. Laravel's built-in slack log channel posts every line at its level to a Slack incoming webhook, one message per line. Or send your logs to Tailcove and create an alert that posts to Slack, which sends one message when errors cross a threshold and one when they stop, with the newest matching lines in it.

Why does Laravel's Slack logging slow down requests?

The slack driver uses Monolog's Slack webhook handler, which posts each line to Slack with a blocking HTTP call inside the request that logged it, and sets no timeout. Tailcove's package sends lines in batches after the response has been sent.

Will Slack get a message every minute while the errors continue?

No. The alert posts once when it fires and once when it resolves. While the count stays above the threshold it doesn't post again, and the cooldown stops a flapping alert from firing more often than you chose.

Can the alert post to Discord or Microsoft Teams instead?

Yes. The Who to tell step also has Discord, Teams, email, SMS and others, and one alert can post to several of them at once.

Next steps#

Ready to try it on your own logs?

The Free plan includes a source, live tail, search and alerts. No credit card.