Challenge - 5 Problems
Laravel Logging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Laravel logging command?
Given the following Laravel code snippet, what will be the output in the log file?
Laravel
<?php use Illuminate\Support\Facades\Log; Log::channel('single')->info('User login successful', ['user_id' => 42]);
Attempts:
2 left
💡 Hint
Check the default log level for the info() method and the 'single' channel behavior.
✗ Incorrect
The info() method logs messages with INFO level. The 'single' channel writes to a single log file, formatting the message with context as JSON.
❓ Configuration
intermediate2:00remaining
Which configuration sets daily log files with 7 days retention?
In Laravel's logging configuration (config/logging.php), which option correctly configures daily logs with retention of 7 days?
Attempts:
2 left
💡 Hint
The 'daily' driver creates a new log file each day and supports 'days' for retention.
✗ Incorrect
The 'daily' driver with 'days' => 7 keeps logs for 7 days. 'single' driver does not support 'days'. 'stack' is for combining channels.
❓ Troubleshoot
advanced2:00remaining
Why does Laravel not log to Slack channel?
A Laravel app is configured to log errors to Slack using the 'slack' channel, but no messages appear in Slack. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check the webhook URL configuration for Slack channel.
✗ Incorrect
Slack logging requires a valid webhook URL. Without it, messages won't be sent. The 'slack' driver is supported. Log level and environment may affect logging but missing webhook is most common cause.
🔀 Workflow
advanced3:00remaining
Order the steps to add a custom log channel in Laravel
Arrange these steps in the correct order to add a custom log channel that writes to a daily rotating file with JSON formatting.
Attempts:
2 left
💡 Hint
Think about defining the tap class before referencing it in config.
✗ Incorrect
First create the tap class (2), register it if needed (3), then add the channel config referencing the tap (1), finally use the channel (4).
✅ Best Practice
expert3:00remaining
Which practice improves Laravel logging performance in high traffic?
In a high traffic Laravel application, which logging practice best improves performance without losing critical logs?
Attempts:
2 left
💡 Hint
Consider how to avoid blocking requests while logging.
✗ Incorrect
Asynchronous logging via queues offloads log writing from request cycle, improving performance. Synchronous logging can slow requests. Disabling logging loses data. Using only 'error' level misses important info.