Drivers

The Logger Driver

Using the Logger driver to log application events and errors.

Introduction

The Logger driver is based on Monolog exposes Monolog Logger object application events and errors in your API.

Installation

Install the driver via composer by running:

composer require kipchak/driver-logger

Initialise the Driver

Add the following line to your drivers/drivers.php file:

\Mamluk\Kipchak\Driver\Logger\Logger::iniitalise($container);

Configuration

The driver reads from the shared kipchak.api.php config file. It has one optional setting of its own.

logProcessors (array, optional)

A list of Monolog processors to push onto the underlying MonoLogger instance before any handler runs. Each entry can be either:

  • A fully-qualified class name (instantiated with no constructor arguments), or
  • An already-constructed processor instance, or
  • Any other PHP callable matching Monolog's processor signature.

The driver ships with no processors of its own — bring your own. This is the hook to add things like credential redaction, request-ID enrichment, or any custom enrichment you need across every log record.

Example Configuration

<?php

return [
    'name' => 'my-api',
    'debug' => false,
    // ...other kipchak.api settings...
    'logProcessors' => [
        \App\Logger\Processors\CredentialRedactingProcessor::class,
        \App\Logger\Processors\RequestIdProcessor::class,
    ],
];

Usage

use Kipchak\Driver\Logger\Logger;

$logger = Logger::get();
$logger->debug('Debug message');
$logger->info('Info message');
$logger->warning('Warning message');
$logger->error('Error message', ['context' => 'data']);

Log level is automatically set based on the debug setting in the kipchak.api.php config file.

Git Repository

The source code for this driver is available on 1x.ax at https://1x.ax/mamluk/kipchak/drivers/logger.

Previous
Config
Next
HTTP