VeldoraDocs

16. PSR-3 Logging

Veldora includes a PSR-3 compliant logger that writes structured log entries to daily rotating log files in storage/logs/. Each log entry includes a timestamp, severity level, message, and optional context array.

Log File Location

Log files are stored at storage/logs/app.log and automatically rotate daily (e.g., app-2026-08-23.log) based on your config/logging.php settings.

Log Levels

Veldora supports all 8 standard PSR-3 log levels, from lowest to highest severity:

LevelHelperUse For
debuglog_debug()Detailed development/diagnostic info
infolog_info()Normal application events (user login, payment processed)
noticelogger()->notice()Normal but significant conditions
warninglogger()->warning()Non-critical issues that should be investigated
errorlog_error()Runtime errors that don't require immediate action
criticallogger()->critical()Critical conditions (component unavailable)
alertlogger()->alert()Action must be taken immediately
emergencylogger()->emergency()System is unusable

Using Global Helpers

example.php
PHP
// Informational events (user actions, successful operations)
log_info('User signed in', [
    'user_id' => $user->id,
    'ip'      => $request->ip(),
    'agent'   => $request->userAgent(),
]);

// Debug info during development
log_debug('Slow query detected', [
    'query'   => $sql,
    'elapsed' => '1250ms',
]);

// Errors that need investigation
log_error('Payment gateway failure', [
    'order_id' => $order->id,
    'gateway'  => 'stripe',
    'error'    => $e->getMessage(),
    'trace'    => $e->getTraceAsString(),
]);

Using the Logger Instance

example.php
PHP
$logger = logger();

$logger->warning('Rate limit approaching threshold', ['attempts' => 95, 'limit' => 100]);
$logger->critical('Database connection lost!', ['host' => config('database.host')]);
$logger->alert('Disk space below 5%', ['free_bytes' => disk_free_space('/'), 'path' => '/']);

Logging in Exception Handlers

A common pattern is to log errors inside try/catch blocks:

example.php
PHP
public function processPayment(Request $request): Response
{
    try {
        $charge = $this->paymentService->charge(
            $request->input('amount'),
            $request->input('card_token')
        );

        log_info('Payment successful', [
            'user_id'    => auth()->id(),
            'amount'     => $charge->amount,
            'charge_id'  => $charge->id,
        ]);

        return Response::redirect('/dashboard')
            ->with('success', 'Payment complete!');

    } catch (\Exception $e) {
        log_error('Payment failed', [
            'user_id' => auth()->id(),
            'error'   => $e->getMessage(),
        ]);

        return Response::redirect('/checkout')
            ->with('error', 'Payment could not be processed. Please try again.');
    }
}

Log Configuration

Adjust the log channel and retention in config/logging.php:

example.php
PHP
return [
    'default' => env('LOG_CHANNEL', 'daily'),

    'channels' => [
        'daily' => [
            'driver' => 'daily',
            'path'   => storage_path('logs/app.log'),
            'days'   => 14,    // Keep logs for 14 days
            'level'  => env('LOG_LEVEL', 'debug'),
        ],
        'single' => [
            'driver' => 'single',
            'path'   => storage_path('logs/app.log'),
            'level'  => 'debug',
        ],
    ],
];


Building with AI Assistants?
Copy the Veldora AI Developer Prompt to teach ChatGPT, Claude, Cursor, or Gemini all framework APIs for error-free coding.