LOGGING

Last updated: June 29th 2026

Overview

Simply PHP ships with structured logging powered by Monolog. The Log facade provides a clean, static API for writing log messages at any PSR-3 log level.

Configuration

Create app/Config/logging.php to configure the log channel:

<?php

return [
    'default'  => env('LOG_CHANNEL', 'daily'),
    'channels' => [
        'daily' => [
            'driver' => 'daily',
            'path'   => env('LOG_PATH', '../simply/logs/simply.log'),
            'level'  => env('LOG_LEVEL', 'debug'),
            'days'   => 14,
        ],
    ],
];

Supported channels: daily (default, rotates daily, keeps 14 days), single, stderr, syslog, errorlog.

Usage

The Log facade supports all PSR-3 log levels as static methods:

use Simple\Log;

Log::debug('Query executed', ['sql' => $sql, 'time' => $ms]);
Log::info('User logged in', ['user_id' => $id]);
Log::notice('Rate limit approached', ['ip' => $ip]);
Log::warning('Disk space low', ['free' => $free]);
Log::error('Failed to send email', ['exception' => $e]);
Log::critical('Database connection lost');
Log::alert('Server is on fire');
Log::emergency('System is down');

Each method accepts a message string and an optional context array for structured data.

Global Context

Attach context that appears on every log entry:

Log::withContext([
    'request_id' => uniqid(),
    'environment' => env('APP_ENV', 'production'),
]);

Log::info('Processing payment'); // includes request_id and environment

Log Levels

The level config option controls which messages are recorded. From lowest to highest severity:

  • debug — verbose diagnostic information
  • info — general application events
  • notice — normal but significant conditions
  • warning — potential issues that are not errors
  • error — runtime errors that should be investigated
  • critical — critical conditions
  • alert — immediate action required
  • emergency — system is unusable

Setting LOG_LEVEL=error in .env will record error and above, but suppress debug, info, notice, and warning.

Error Handler Integration

When SHOW_ERRORS=false in production, the framework's error handler automatically logs all exceptions and errors via Monolog with full stack traces:

// Automatically logged by Error::exceptionHandler():
// [2026-06-24 01:54:04 PM] ERROR: Undefined constant "VERSIONs"
// #0 /var/www/html/app/Controllers/HomeController.php(20): ...
// #1 /var/www/framework/src/Simple/Routing/BaseRouter.php(241): ...

You can switch the error presentation between Whoops (pretty pages) and Simply (logged-only in production) via the ERROR_HANDLER env var — see the FAQ.