Marwa Framework uses PSR-3 compatible logging with support for multiple channels, sensitive data filtering, and structured log formatting.
Logging is configured in config/logger.php:
return [
'enable' => env('APP_DEBUG', false),
'filter' => [
'password',
'secret',
'token',
],
'level' => 'debug',
'storage' => [
'driver' => env('LOG_CHANNEL', 'file'),
'path' => storage_path('logs'),
'prefix' => 'marwa',
],
];
Available log levels (from most to least severe):
| Level | Description |
|---|---|
emergency |
System is unusable |
alert |
Immediate action required |
critical |
Critical conditions |
error |
Error conditions |
warning |
Warning conditions |
notice |
Normal but significant |
info |
Informational messages |
debug |
Debug-level messages |
use Psr\Log\LoggerInterface;
// Via dependency injection
class UserController
{
public function __construct(
private LoggerInterface $logger
) {}
public function store(Request $request)
{
$this->logger->info('User created', [
'user_id' => $user->id,
'email' => $request->get('email'),
]);
}
}
// Via helper function
logger()->error('Something went wrong', [
'exception' => $e->getMessage(),
]);
Configure different storage drivers:
// config/logger.php
'storage' => [
'driver' => 'file', // file, daily, syslog, errorlog, null
'path' => storage_path('logs'),
'prefix' => 'marwa',
],
Automatically filter sensitive values from logs:
// config/logger.php
'filter' => [
'password',
'password_confirmation',
'secret',
'token',
'api_key',
'credit_card',
],
Filtered values are replaced with [Filtered] in logs.
logger()->info('User logged in', [
'user_id' => $user->id,
'ip' => request()->getClientIp(),
'user_agent' => request()->getHeader('User-Agent'),
]);
try {
// code
} catch (\Exception $e) {
logger()->error('Operation failed', [
'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
]);
}
Default log locations:
storage/logs/
├── marwa.log # Default log file
├── marwa-2026-01-01.log # Daily logs (when using daily driver)
APP_DEBUG=true
LOG_CHANNEL=file
APP_DEBUG=false
LOG_CHANNEL=file
// config/logger.php
'enable' => false,
The framework uses Marwa\Logger\SimpleLogger which provides:
logger()->emergency('System down');
logger()->alert('Database connection lost');
logger()->critical('File not found');
logger()->error('Operation failed');
logger()->warning('Deprecated method');
logger()->notice('User logged in');
logger()->info('Cache cleared');
logger()->debug('Query executed');
info