0
0
Laravelframework~10 mins

Logging configuration in Laravel - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Logging configuration
Start Laravel App
Load logging config from config/logging.php
Select log channel (e.g., stack, single, daily)
Initialize log handler (file, syslog, errorlog, etc.)
App runs and logs messages
Messages written to log destination
End
Laravel loads logging settings, chooses the channel, initializes handlers, then writes log messages during app execution.
Execution Sample
Laravel
<?php
Log::info('User logged in');
Log::error('Payment failed');
This code writes an info and an error message to the configured log channel.
Execution Table
StepActionLog LevelMessageLog DestinationResult
1Call Log::info()infoUser logged instorage/logs/laravel-YYYY-MM-DD.log (daily)Message appended to log file
2Call Log::error()errorPayment failedstorage/logs/laravel-YYYY-MM-DD.log (daily)Message appended to log file
3No more log calls---Logging complete for this request
💡 All log calls processed, messages saved to daily log file
Variable Tracker
VariableStartAfter Step 1After Step 2Final
Log Channeldailydailydailydaily
Log Filestorage/logs/laravel-YYYY-MM-DD.logstorage/logs/laravel-YYYY-MM-DD.logstorage/logs/laravel-YYYY-MM-DD.logstorage/logs/laravel-YYYY-MM-DD.log
Log Messages[]["info: User logged in"]["info: User logged in", "error: Payment failed"]["info: User logged in", "error: Payment failed"]
Key Moments - 2 Insights
Why do both info and error messages go to the same log file?
Because the configured log channel is 'daily' which writes all levels to the same daily log file, as shown in execution_table steps 1 and 2.
What happens if the log channel is changed to 'single'?
The log messages would still be written to a single log file, but without daily rotation. The destination path changes, but the process is similar.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the log level of the message logged at step 2?
Ainfo
Berror
Cwarning
Ddebug
💡 Hint
Check the 'Log Level' column in row for step 2 in the execution_table.
At which step does the log message 'User logged in' get written?
AStep 1
BStep 2
CStep 3
DIt is never written
💡 Hint
Look at the 'Message' column in execution_table for step 1.
If the log channel was changed to 'errorlog', how would the log destination change?
AMessages would be discarded
BMessages would be saved in storage/logs/laravel.log
CMessages would be sent to system error log instead of a file
DMessages would be sent to a database
💡 Hint
Refer to Laravel logging channels and their destinations in the concept_flow.
Concept Snapshot
Laravel logging config is set in config/logging.php
Choose a log channel (daily, single, errorlog, etc.)
Log calls write messages to the channel's destination
Daily channel writes to storage/logs/laravel-YYYY-MM-DD.log with rotation
Log levels (info, error) are all recorded in the chosen channel
Full Transcript
Laravel starts by loading the logging configuration from config/logging.php. It selects the log channel, such as 'daily', which writes logs to a daily rotated file. When the app runs, calls like Log::info and Log::error write messages to the log file. Each message includes a level and text. The execution table shows step 1 logs an info message 'User logged in' to the daily log file. Step 2 logs an error message 'Payment failed' to the same file. After all log calls, the messages are saved and logging ends for the request. Variables like Log Channel and Log File remain constant, while Log Messages accumulate entries. Beginners often wonder why different levels go to the same file; this is because the channel handles all levels together. Changing the channel changes the destination but not the logging process. The visual quiz tests understanding of log levels, steps when messages are logged, and effects of changing channels.