ErrorLog Adapter
This adapter uses the PHP error_log()
function internally. This provides flexibility in the log
target with a single adapter. For example, you can send the log to email, a text file, or PHP’s system
logger. See the PHP manual for more details.
The current message types are:
ErrorLog::TYPE_PHP_LOG; // equivalent to message type 0 in error_log()
ErrorLog::TYPE_EMAIL; // equivalent to message type 1 in error_log()
ErrorLog::TYPE_FILE; // equivalent to message type 3 in error_log()
ErrorLog::TYPE_SAPI_LOG; // equivalent to message type 4 in error_log()
<?php
use Vespula\Log\Log;
use Vespula\Log\Adapter\ErrorLog;
// Send to PHP's system logger
ini_set('error_log', '/myapp/logs/mylog.txt');
$adapter = new ErrorLog(); // ErrorLog::TYPE_PHP_LOG is the default (php system logger)
// Note, you will probably want to modify the message format to omit the timestamp
// because PHP's system logger automatically adds a timestamp.
$adapter->setMessageFormat("[{level}]\t{message}");
$log = new Log($adapter);
$log->info('Some message');
// Send to a specific file
$adapter = ErrorLog(ErrorLog::TYPE_FILE, '/myapp/logs/mylog.txt');
// Send to email
$headers = [
'From: donotreply@myapp.com',
'Subject: MyApp LogEntry'
];
$header_string = implode("\r\n", $headers);
$adapter = new ErrorLog(ErrorLog::TYPE_EMAIL, 'juser@happy.com', $header_string);
$log = new Log($adapter);
$log->info('Some message');
// You might not want to use this unless you are logging serious events.
// Your inbox might get filled up fast.