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 inconfig/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
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:debug-and-above messages go to the daily file, while only critical and higher are sent to Slack.
The daily channel
Rotate log files by date and delete old ones automatically:Slack error notifications
Get your Incoming Webhook URL from Slack and add it to.env:
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 withLog::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
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
Choosing a log level
Choosing a log level
Choosing a channel
Choosing a channel
- Development:
singleordailyto write to a file - Production:
stackcombiningdaily(file) andslack(critical alerts) - Isolated processes:
Log::build()for a dedicated log file per job or import - Real-time monitoring:
php artisan pailin the terminal
Production considerations
Production considerations
debuglogs may contain sensitive data. UseLOG_LEVEL=erroror higher in production.- Rotate log files regularly with the
dailychannel and an appropriatedaysvalue. - Be mindful of rate limits on external services like Slack — route only critical alerts there.