aqilix/zf3-psr3-logger

PSR3 Logger for ZF3 and ZF2 Application

0.0.2 2017-08-16 12:33 UTC

This package is not auto-updated.

Last update: 2024-04-08 13:26:12 UTC


README

This is a simple module for loading logger using PSR3 to your ZF3/ZF2 application. By default the logger will write to a file (data/log/system.log). But you can override the logger configuration by override logger in autoload/*.local.php. By using this module you don't need to write delegators to modify the logger from Zend\Log.

Installation

Add zf3-psr3-logger to composer.json

composer require aqilix/zf3-psr3-logger

Add Aqilix\\ZF3PSR3Logger to config/modules.config.php

Usage

Inject psr3_logger service into class that wanna use logger. If using factories we can do it like this

public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
    $example = new Example();
    $example->setLogger($container->get("psr3_logger"));
    return $example;
}

And here the Example class

class Example
{
    use Psr\Log\LoggerAwareTrait;

    public function test()
    {
        $this->logger->log(\Psr\Log\LogLevel::INFO, "{function} Testing logger", ["function" => __FUNCTION__]);
        $this->logger->log(\Psr\Log\LogLevel::ERROR, "{function} Testing logger", ["function" => __FUNCTION__]);
    }
}