Skip to content

Logger Methods

All methods accept a message string and optional context array:

MethodLevelUse When
$log->emergency($msg, $ctx)EmergencySystem is unusable
$log->alert($msg, $ctx)AlertImmediate action required
$log->critical($msg, $ctx)CriticalCritical conditions
$log->error($msg, $ctx)ErrorRuntime errors
$log->warning($msg, $ctx)WarningExceptional occurrences not errors
$log->notice($msg, $ctx)NoticeNormal but significant
$log->info($msg, $ctx)InfoInteresting events
$log->debug($msg, $ctx)DebugDetailed debug information
MethodDescription
$log->withContext($context)Add default context to all messages
$log->channel($name)Create logger with channel in context
$log->info('User logged in');
$log->error('Database connection failed');
$log->debug('Query executed', ['sql' => $sql, 'time' => $duration]);
$log->info('Payment processed', [
'user_id' => 123,
'amount' => 50.00,
'method' => 'credit_card'
]);
$log = $log->withContext(['request_id' => generateId()]);
$log->info('Processing started'); // Includes request_id
$log->info('Processing complete'); // Includes request_id
$userLog = $log->channel('users');
$paymentLog = $log->channel('payments');
$userLog->info('User created', ['id' => 123]);
$paymentLog->info('Payment succeeded', ['amount' => 99.99]);
try {
riskyOperation();
} catch (Exception $e) {
$log->error('Operation failed', [
'error' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine()
]);
}