PHP code example of seyfer / zend-psr-logger

1. Go to this page and download the library: Download seyfer/zend-psr-logger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

seyfer / zend-psr-logger example snippets


'logger'        => array(
        'registeredLoggers' => array(
            'DefaultLogger' => array(
                'entityClassName' => '\ZendPsrLogger\Entity\DefaultLog',
                'columnMap'       => array(
                    'timestamp'    => 'timestamp',
                    'priority'     => 'priority',
                    'priorityName' => 'priorityName',
                    'message'      => 'message',
                    'extra'        => array(
                        'ipaddress' => 'ipaddress',
                    ),
                )
            ),
            'ElseDefaultLogger' => array(
                'entityClassName' => '\ZendPsrLogger\Entity\ElseDefaultLog',
                'columnMap'       => array(
                    'timestamp'    => 'timestamp',
                    'priority'     => 'priority',
                    'priorityName' => 'priorityName',
                    'message'      => 'message',
                    'extra'        => array(
                        'fileName' => 'fileName',
                    ),
                )
            )
        ),
    ),

public function getServiceConfig()
    {
        return array(
            'abstract_factories' => array(
                'DefaultLogger' => '\ZendPsrLogger\Service\AbstractLoggerFactory',
                'ElseDefaultLogger' => '\ZendPsrLogger\Service\AbstractLoggerFactory',
            ),
        );
    }

use ZendPsrLogger\LoggerInterface;
use ZendPsrLogger\NullLogger;
...

/** @var type LoggerInterface */
$this->logger
...

if ($this->getServiceLocator()->has($myLoggerName)) {
    $logger = $this->getServiceLocator()->get($myLoggerName);
} else {
    $logger = new NullLogger();
}

$this->logger = $logger;

$this->logger->addExtra(['ipaddress' => '11.22.33.44']);
$this->logger->debug("test");

$this->logger->log(\Psr\Log\LogLevel::DEBUG, "test", ['ipaddress' => '11.22.33.44']);