Using Multiple Adapters

You may want more than one log adapter. For example, one that logs everything above INFO to a file, and one that only logs CRITICAL and higher to email.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?php
use Vespula\Log\Log;
use Vespula\Log\Adapter\ErrorLog;
use Psr\Log\LogLevel;

$file_adapter = new ErrorLog(ErrorLog::TYPE_FILE, '/path/to/log.txt');
$file_adapter->setMinLevel(LogLevel::INFO); // Debug won't be logged

$email_adapter = new ErrorLog(ErrorLog::TYPE_EMAIL, 'admin@mysite.org', 'Subject: Major Error on Site');
$email_adapter->setMinLevel(LogLevel::CRITICAL); //CRITICAL and higher will be logged by email

$log = new Log($file_adapter); //default adapter
$log->addAdapter($email_adapter);

$log->alert('This is really bad'); // Goes to both adapters
$log->warning('This is not too horrible'); // only logged in the file.