Monolog Handler Example
A Handler that writes to the FreePBX KV Store
MonologKVStore.php
<?php
namespace FreePBX\modules\Module\Handlers;
use Monolog\Logger;
use Monolog\Handler\AbstractProcessingHandler;
class MonologKVStore extends AbstractProcessingHandler{
private $module;
public function __construct($moduleObj, $level = Logger::INFO, $bubble = true){
$this->module = $moduleObj;
parent::__construct($level,$bubble);
}
protected function write(array $record){
$this->module->setConfig($record['datetime']->format('U'),$record,'monolog');
}
} |
Adding your handler:
Module.class.php
<?php
use FreePBX\modules\Backup\Handlers as Handler;
.....
$logger = $this->FreePBX->Logger;
$handler = new Handler\MonologHandler($this);
$logger->monolog->pushHandler($handler);
..... |