Docs LATEST

FileLogger

API reference for VelvetCMS\Services\FileLogger.

Services

Namespace: VelvetCMS\Services\FileLogger


FileLogger is the built-in PSR-3 logger used by the core container binding behind app('logger').

For config values such as log level and daily rotation, see Logging Configuration.

Definition #

class FileLogger implements LoggerInterface
{
    public function __construct(
        ?string $logPath = null,
        string $level = LogLevel::INFO,
        bool $daily = false,
        int $maxFiles = 7
    );

    public function emergency(string|Stringable $message, array $context = []): void;
    public function alert(string|Stringable $message, array $context = []): void;
    public function critical(string|Stringable $message, array $context = []): void;
    public function error(string|Stringable $message, array $context = []): void;
    public function warning(string|Stringable $message, array $context = []): void;
    public function notice(string|Stringable $message, array $context = []): void;
    public function info(string|Stringable $message, array $context = []): void;
    public function debug(string|Stringable $message, array $context = []): void;
    public function log($level, string|Stringable $message, array $context = []): void;

    public function getLogPath(): string;
}

Behavior notes #

  • Messages below the configured threshold are ignored.
  • Context placeholders such as {user_id} are interpolated before writing.
  • If daily is enabled, the logger writes to date-stamped files and removes older files when the count exceeds maxFiles.
  • If the context includes an exception entry that contains a Throwable, the exception details and stack trace are appended to the log entry.

Example #

$logger = app('logger');

$logger->info('User logged in', ['user_id' => 42]);
$logger->error('Payment failed for order {order}', [
    'order' => 9012,
    'exception' => $e,
]);