0
0
Laravelframework~20 mins

Logging configuration in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Logging Configuration in Laravel
📖 Scenario: You are building a Laravel web application that needs to keep track of important events and errors. Proper logging helps developers find and fix problems quickly.
🎯 Goal: Configure Laravel logging to write logs to a single file and then customize the log level to only record warnings and errors.
📋 What You'll Learn
Create a logging configuration array in config/logging.php with a single channel named single that writes to storage/logs/laravel.log
Add a variable logLevel set to warning to control the minimum log level
Modify the single channel to use the logLevel variable for its level setting
Print the current log channel and log level to verify the configuration
💡 Why This Matters
🌍 Real World
Logging is essential in real applications to track errors and important events. Laravel uses configuration files to manage logging behavior.
💼 Career
Understanding logging configuration helps developers and DevOps engineers monitor applications and troubleshoot issues efficiently.
Progress0 / 4 steps
1
Create basic logging configuration
Create a PHP array called loggingConfig with a key channels that contains a single channel. The single channel should have driver set to single and path set to storage/logs/laravel.log.
Laravel
Need a hint?

Use a PHP array with nested arrays for channels and the single channel configuration.

2
Add log level configuration variable
Add a variable called logLevel and set it to the string 'warning'.
Laravel
Need a hint?

Declare a simple string variable named logLevel with value 'warning'.

3
Set log level in the single channel
Add a level key to the single channel inside $loggingConfig and set its value to the variable $logLevel.
Laravel
Need a hint?

Inside the single array, add 'level' => $logLevel.

4
Print the current log channel and level
Write two print statements to display the current log channel name 'single' and the log level stored in $logLevel.
Laravel
Need a hint?

Use print("Current log channel: single\n") and print("Log level: $logLevel\n").