LogFactory::createStreamHandler()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 8
rs 10
ccs 0
cts 5
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of forecast.it.fill project.
7
 * (c) Patrick Jaja <[email protected]>
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace ForecastAutomation\Log;
13
14
use ForecastAutomation\Kernel\AbstractFacade;
15
use ForecastAutomation\Log\Business\Logger;
16
use Monolog\Formatter\JsonFormatter;
17
use Monolog\Handler\LogglyHandler;
18
use Monolog\Handler\StreamHandler;
19
use Monolog\Logger as MonologLogger;
20
use Monolog\Processor\UidProcessor;
21
22
class LogFactory extends AbstractFacade
23
{
24
    public function createLogger(): Logger
25
    {
26
        return new Logger($this->createMonologger());
27
    }
28
29
    public function createMonologger(): MonologLogger
30
    {
31
        return (new MonologLogger($_ENV['APPLICATION_NAME']))
32
            ->setHandlers(
33
                [
34
                    $this->createStreamHandler(),
35
                    $this->createLogglyStreamHandler(),
36
                ]
37
            )
38
        ;
39
    }
40
41
    public function createLogglyStreamHandler(): LogglyHandler
42
    {
43
        return new LogglyHandler($_ENV['LOGGLY_CUSTOMER_TOKEN']);
44
    }
45
46
    public function createStreamHandler(): StreamHandler
47
    {
48
        $handler = new StreamHandler($this->getLogPath());
49
50
        $handler->setFormatter(new JsonFormatter());
51
        $handler->pushProcessor(new UidProcessor(32));
52
53
        return $handler;
54
    }
55
56
    public function getLogPath(): string
57
    {
58
        return 'php://stdout';
59
    }
60
}
61