antidot-fw/logger

Anti.Framework logger adapter library

1.1.2 2021-01-10 11:27 UTC

This package is auto-updated.

Last update: 2023-05-30 14:01:57 UTC


README

Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status Maintainability

Application PSR-15 logger middleware:

  • RequestLoggerMiddleware
  • ExceptionLoggerMiddleware

Installation

Require package with composer package manager.

composer require antidot-fw/logger

Add both Middleware to your Pipeline

<?php
// with Antidot Framework, Zend Expressive or Zend Stratigility

$app->pipe(\Antidot\Logger\Application\Http\Middleware\ExceptionLoggerMiddleware::class);
$app->pipe(\Antidot\Logger\Application\Http\Middleware\RequestLoggerMiddleware::class);

Using Zend Config Aggregator

It installs the library automatically

To use both middlewares in Zend Expressive you need to create factory classes

<?php
// src/App/Container/ExceptionLoggerMiddlewareFactory.php

namespace App\Container;

use Antidot\Logger\Application\Http\Middleware\ExceptionLoggerMiddleware;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

class ExceptionLoggerMiddlewareFactory
{
    public function __invoke(ContainerInterface $container)
    {
        return new ExceptionLoggerMiddleware($container->get(LoggerInterface::class));
    }
}
<?php
// src/App/Container/RequestLoggerMiddlewareFactory.php

namespace App\Container;

use Antidot\Logger\Application\Http\Middleware\RequestLoggerMiddleware;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

class RequestLoggerMiddlewareFactory
{
    public function __invoke(ContainerInterface $container)
    {
        return new RequestLoggerMiddleware($container->get(LoggerInterface::class));
    }
}

Using factory:

Config

See wshafer/psr11-monolog for complete config reference, it allows using some different handlers

factory

<?php

use Antidot\Logger\Container\MonologFactory;
use Psr\Log\LoggerInterface;

$factory = new MonologFactory();

$logger = $factory->__invoke($container);
$container->set(LoggerInterface::class, $logger);