Using Custom Logger

Default PHP runtime logger can be replaced with a custom one. This example shows how to use Zend logger:

<?php

class ZendApsLoggerAdapter implements \APS\LoggerInterface
{
    /** @var \Zend\Log\Logger */
    private $_zendLogger;

    /**
     * @param \Zend\Log\Logger $zendLogger
     */
    public function __construct($zendLogger)
    {
        $this->_zendLogger = $logger;
    }

    public function trace($message)
    {
        // \Zend\Log\Logger hasn't method 'trace()'.
        $this->_zendLogger->debug('[TRACE] ' . $message);
    }

    public function debug($message)
    {
        $this->_zendLogger->debug($message);
    }

    public function info($message)
    {
        $this->_zendLogger->info($message);
    }

    public function error($message)
    {
        $this->_zendLogger->err($message);
    }

    public function fatal($message)
    {
        $this->_zendLogger->crit($message);
    }
}

$zendLogger = new \Zend\Log\Logger;
$writer = new \Zend\Log\Writer\Stream('/tmp/plesk.panel.log');
$zendLogger->addWriter($writer);

\APS\LoggerRegistry::set(new \pvps\Log\ZendApsLoggerAdapter($zendLogger));