0
0
Laravelframework~20 mins

Logging configuration in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Laravel Logging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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]);
A[ERROR] User login successful {"user_id":42}
BNo output, because the channel 'single' is not defined
CUser login successful
D[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.
Configuration
intermediate
2: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?
A'daily' => [ 'driver' => 'stack', 'channels' => ['single'], 'days' => 7 ]
B'daily' => [ 'driver' => 'daily', 'path' => storage_path('logs/laravel.log'), 'days' => 7 ]
C'daily' => [ 'driver' => 'daily', 'path' => storage_path('logs/laravel.log'), 'days' => 30 ]
D'daily' => [ 'driver' => 'single', 'path' => storage_path('logs/laravel.log'), 'days' => 7 ]
Attempts:
2 left
💡 Hint
The 'daily' driver creates a new log file each day and supports 'days' for retention.
Troubleshoot
advanced
2: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?
AThe log level is set to 'debug' instead of 'error'.
BThe 'slack' driver is not supported by Laravel.
CThe Slack webhook URL is missing or incorrect in the logging config.
DThe app is running in local environment which disables all logging.
Attempts:
2 left
💡 Hint
Check the webhook URL configuration for Slack channel.
🔀 Workflow
advanced
3: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.
A2,3,1,4
B3,2,1,4
C2,1,3,4
D1,2,3,4
Attempts:
2 left
💡 Hint
Think about defining the tap class before referencing it in config.
Best Practice
expert
3: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?
AUse asynchronous logging with a queue to handle log writes.
BLog all messages synchronously to a single file to avoid missing logs.
CDisable logging in production to save resources.
DUse the 'error' log level for all messages to reduce log size.
Attempts:
2 left
💡 Hint
Consider how to avoid blocking requests while logging.