Documentation Index
Fetch the complete documentation index at: https://kawax.biz/llms.txt
Use this file to discover all available pages before exploring further.
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
| Driver | Description |
|---|---|
single | Writes all log messages to one file |
daily | Rotates log files daily and removes old ones |
slack | Sends messages to a Slack Incoming Webhook |
stack | Aggregates multiple channels into one |
syslog | Writes to the system syslog |
errorlog | Writes to PHP’s error log |
monolog | Uses a Monolog handler directly |
custom | Calls a factory class to build the channel |
Log levels
Laravel supports the eight log levels defined in RFC 5424, from highest to lowest severity:| Level | When to use |
|---|---|
emergency | System is unusable; immediate action required |
alert | Action must be taken immediately (e.g., database down) |
critical | Critical conditions; a core feature has stopped working |
error | Runtime errors that require attention |
warning | Unexpected behavior that is not yet an error |
notice | Normal but significant events |
info | Informational messages (logins, orders confirmed, etc.) |
debug | Detailed debug information for development |
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. Every log entry for that request now includesrequest-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
| Level | Use when |
|---|---|
emergency | The system is completely unusable |
alert | A human must act immediately |
critical | A core feature has stopped working |
error | An unexpected runtime error occurred |
warning | Something unexpected that is not yet an error |
notice | A normal but notable event |
info | A user action or business event to track |
debug | Detailed information for debugging (not for production) |
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.