LoggerFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Acelaya\Website\Factory;
5
6
use Interop\Container\ContainerInterface;
7
use Interop\Container\Exception\ContainerException;
8
use Monolog\Formatter\LineFormatter;
9
use Monolog\Handler\StreamHandler;
10
use Monolog\Logger;
11
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
12
use Zend\ServiceManager\Exception\ServiceNotFoundException;
13
use Zend\ServiceManager\Factory\FactoryInterface;
14
15
class LoggerFactory implements FactoryInterface
16
{
17
    /**
18
     * Create an object
19
     *
20
     * @param  ContainerInterface $container
21
     * @param  string $requestedName
22
     * @param  null|array $options
23
     * @return object
24
     * @throws ServiceNotFoundException if unable to resolve the service.
25
     * @throws ServiceNotCreatedException if an exception is raised when
26
     *     creating a service.
27
     * @throws ContainerException if any other error occurs
28
     */
29
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
30
    {
31
        $loggerConfig = $container->get('config')['logger'];
32
        $isDebug = $container->get('config')['debug'] ?? false;
33
34
        $formatter = new LineFormatter('[%datetime%] %channel%.%level_name% - %message% %context%' . PHP_EOL);
35
        $formatter->includeStacktraces();
36
37
        $handler = new StreamHandler($loggerConfig['file'], $isDebug ? Logger::DEBUG : Logger::INFO);
38
        $handler->setFormatter($formatter);
39
40
        return new Logger('alejandrocelaya.com', [$handler]);
41
    }
42
}
43