File Adapter

The file adapter uses PHP’s error_log() function to write the log to a file.

<?php
use Vespula\Log\Adapter\File as FileAdapter;
use Vespula\log\Adapter\Log;

$file = '/tmp/mylog.txt';

$adapter = new FileAdapter($file);

$log = new Log($adapter);

$log->info('This is informative');

$context = [
    'id'=>45
];
$log->error('Failed to update record {id}', $context);

Retrieving Entries

By default, it will return all entries ordered in descending order (Last in, First out).

<?php
// Get all entries
$entries = $log->getAdapter()->getEntries();

// Get only 10 entries
$entries = $log->getAdapter()->getEntries(10);

// Get 10 entries starting on page 2
$entries = $log->getAdapter()->getEntries(10, 2);

// Get all entries, but first in, first out (ascending order)
$entries = $log->getAdapter()->getEntries(0, 0, false);

// Get a count of all entries
$count = $log->getAdapter()->getCount();

You can pair this nicely with Vespula.Paginator