Skip to main content

What is logging?

Laravel’s logging system is organized around channels — named configurations that define where and how log messages are written. A single log call can write to multiple channels simultaneously: a rotating daily file, a Slack webhook, or a custom handler. Internally, Laravel uses the Monolog library, giving you access to a wide range of handlers and formatters.
The default channel is stack. A stack channel aggregates multiple channels so one log call reaches all of them.

Configuration

Logging configuration lives in config/logging.php. Set the default channel with the LOG_CHANNEL environment variable:

Available channel drivers

Log levels

Laravel supports the eight log levels defined in RFC 5424, from highest to lowest severity: A channel’s level setting is a minimum threshold. A channel set to error only records error, critical, alert, and emergency messages.

Writing log messages

The Log facade

Use context to include structured data alongside the message:

The log helper

Write a log entry without importing the facade:

Contextual information

Pass an array as the second argument to include related data:

withContext — add context to a channel

Attach context that will appear on all subsequent log entries for the current channel. Useful for request IDs:

shareContext — add context to all channels

withContext affects only the current channel. shareContext applies to all channels:

Channel configuration

The stack channel

Write to multiple channels with a single log call:
With this configuration, all debug-and-above messages go to the daily file, while only critical and higher are sent to Slack.
In production, set the Slack channel level to error or critical. Routing every log message to Slack creates noise and buries the alerts that matter.

The daily channel

Rotate log files by date and delete old ones automatically:
A short days value means old logs are deleted quickly. Keep enough history to diagnose production incidents.

Slack error notifications

Get your Incoming Webhook URL from Slack and add it to .env:
Include slack in the stack channel and set LOG_CHANNEL=stack to receive automatic Slack alerts when errors occur.

Writing to a specific channel

On-demand channels

Build a channel at runtime with Log::build() — no configuration file entry needed. Useful for temporary output or isolated log files per job:

Practical example: attaching a request ID in middleware

Adding a unique request ID to every log entry makes it easy to trace a single request through your logs.
1

Create the middleware

2

Implement handle()

3

Register the middleware globally

Every log entry for that request now includes request-id:

Deprecation warnings

Log PHP and Laravel deprecation warnings to catch them before they become breaking changes:

Laravel Pail — real-time log tailing

Laravel Pail streams your application’s log output directly in the terminal.
Pail requires the PHP PCNTL extension.

Install

Tail logs

Filter output

Summary

  • Development: single or daily to write to a file
  • Production: stack combining daily (file) and slack (critical alerts)
  • Isolated processes: Log::build() for a dedicated log file per job or import
  • Real-time monitoring: php artisan pail in the terminal
  • debug logs may contain sensitive data. Use LOG_LEVEL=error or higher in production.
  • Rotate log files regularly with the daily channel and an appropriate days value.
  • Be mindful of rate limits on external services like Slack — route only critical alerts there.
Last modified on March 29, 2026