PSR-3 compatible logging service for the DarkenPHP framework. This service provides standard logging capabilities following PSR-3 standards and integrates seamlessly with the framework's dependency injection container.
Features:
Usage Examples:
Basic logging:
$logger = $kernel->getLogService();
$logger->info('User logged in', ['user_id' => 123]);
$logger->error('Database connection failed', ['host' => 'localhost']);
Message interpolation:
$logger->info('User {username} performed {action}', [
'username' => 'john_doe',
'action' => 'login'
]); // Results in: "User john_doe performed login"
Retrieving logs:
$allLogs = $logger->getLogs();
$errorLogs = $logger->getLogsByLevel('error');
$logger->clearLogs();
Debug bar integration:
$debugBar = new SomeDebugBar();
$logs = $app->getLogService()->getLogs();
$debugBar->addLogs($logs);
| getLogs() |
|---|
| getLogsByLevel(string $level) |
| clearLogs() |
| log( $level, string|Stringable $message, array $context) |
Get all stored logs. Returns an array of all log entries with their level, message, context, and timestamp. Useful for debugging, testing, and integration with debug tools.
| Return | array |
Get logs filtered by specific level. Filters and returns only log entries that match the specified level. Useful for analyzing specific types of log entries.
| $level | string |
| Return | array |
Clear all stored logs. Removes all log entries from memory. Useful for testing or when you want to start fresh log collection.
| Return | void |
Logs with an arbitrary level. This is the core logging method that all PSR-3 log level methods delegate to. Implements message interpolation according to PSR-3 specifications.
Message placeholders are replaced with values from the context array. Placeholder format: {key} where 'key' corresponds to a context array key.
| $level | |
| $message | string|Stringable |
| $context | array |
| Return | void |