Beginner LevelLaravel
How does Laravel Logging work using Monolog channels and stack configuration?
❓ Interview Prompt: Explain Log facade, Monolog channels (single, daily, slack, stderr), config/logging.php, and log levels.
Laravel uses Monolog to support flexible logging channels configured in 'config/logging.php'.
Channels & Levels:
•
Channels: 'single' (file), 'daily' (rotating date files), 'slack' (webhook notifications), 'stderr'.
•
Log Facade: Provides PSR-3 log levels: 'Log::emergency()', 'Log::error()', 'Log::warning()', 'Log::info()', 'Log::debug()'.
Code Implementation Example
php
<?php
use IlluminateSupportFacadesLog;
try {
// ... database operation
} catch (Throwable $e) {
Log::error('Payment processing failed', [
'user_id' => $user->id,
'error' => $e->getMessage(),
]);
}💡Logging error messages with contextual payload data using Log facade.
🎯 Interview Key Takeaway
Use Log facade methods with contextual array payloads to output structured logs across Monolog channels.
#Logging#Monolog#Log Facade#Beginner
Back to all Laravel Questions→