Issues (3641)

Application/Log/Config/SprykerLoggerConfig.php (5 issues)

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace Spryker\Shared\Application\Log\Config;
9
10
use Monolog\Formatter\LineFormatter;
11
use Monolog\Formatter\LogstashFormatter;
12
use Monolog\Handler\FilterHandler;
13
use Monolog\Handler\StreamHandler;
14
use Monolog\Logger;
15
use Monolog\Processor\PsrLogMessageProcessor;
16
use Spryker\Shared\Application\Log\Processor\EntitySanitizerProcessor;
17
use Spryker\Shared\Application\Log\Processor\EnvironmentProcessor;
18
use Spryker\Shared\Application\Log\Processor\GuzzleBodyProcessor;
19
use Spryker\Shared\Application\Log\Processor\RequestProcessor;
20
use Spryker\Shared\Application\Log\Processor\ResponseProcessor;
21
use Spryker\Shared\Application\Log\Processor\ServerProcessor;
22
use Spryker\Shared\Config\Config;
23
use Spryker\Shared\Log\Config\LoggerConfigInterface;
24
use Spryker\Shared\Log\LogConstants;
25
use Spryker\Shared\Log\Sanitizer\Sanitizer;
26
27
class SprykerLoggerConfig implements LoggerConfigInterface
28
{
29
    /**
30
     * @return string
31
     */
32
    public function getChannelName()
33
    {
34
        return 'Spryker';
35
    }
36
37
    /**
38
     * @return array<\Monolog\Handler\HandlerInterface>
39
     */
40
    public function getHandlers()
41
    {
42
        $handler = [
43
            $this->createStreamHandler(),
44
        ];
45
46
        if (Config::hasKey(LogConstants::EXCEPTION_LOG_FILE_PATH)) {
47
            $handler[] = $this->createExceptionHandler();
48
        }
49
50
        return $handler;
51
    }
52
53
    /**
54
     * @return array<callable>
55
     */
56
    public function getProcessors()
57
    {
58
        $sanitizer = new Sanitizer(
59
            Config::get(LogConstants::LOG_SANITIZE_FIELDS, []),
60
            Config::get(LogConstants::LOG_SANITIZED_VALUE, '***'),
61
        );
62
63
        return [
64
            new PsrLogMessageProcessor(),
65
            new EntitySanitizerProcessor($sanitizer),
0 ignored issues
show
Deprecated Code introduced by
The class Spryker\Shared\Applicati...ntitySanitizerProcessor has been deprecated: Use {@link \Spryker\Zed\Propel\Communication\Plugin\Log\EntityProcessorPlugin} instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

65
            /** @scrutinizer ignore-deprecated */ new EntitySanitizerProcessor($sanitizer),
Loading history...
66
            new EnvironmentProcessor(),
0 ignored issues
show
Deprecated Code introduced by
The class Spryker\Shared\Applicati...or\EnvironmentProcessor has been deprecated: Use `EnvironmentProcessor` of Log module instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

66
            /** @scrutinizer ignore-deprecated */ new EnvironmentProcessor(),
Loading history...
67
            new ServerProcessor(),
0 ignored issues
show
Deprecated Code introduced by
The class Spryker\Shared\Applicati...ocessor\ServerProcessor has been deprecated: Use `ServerProcessorPlugin`s from Log module instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

67
            /** @scrutinizer ignore-deprecated */ new ServerProcessor(),
Loading history...
68
            new RequestProcessor($sanitizer),
0 ignored issues
show
Deprecated Code introduced by
The class Spryker\Shared\Applicati...cessor\RequestProcessor has been deprecated: Use `RequestProcessorPlugin`s from Log module instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

68
            /** @scrutinizer ignore-deprecated */ new RequestProcessor($sanitizer),
Loading history...
69
            new ResponseProcessor(),
0 ignored issues
show
Deprecated Code introduced by
The class Spryker\Shared\Applicati...essor\ResponseProcessor has been deprecated: Use `ResponseProcessorPlugin`s from Log module instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

69
            /** @scrutinizer ignore-deprecated */ new ResponseProcessor(),
Loading history...
70
            new GuzzleBodyProcessor($sanitizer),
71
        ];
72
    }
73
74
    /**
75
     * @return \Monolog\Handler\StreamHandler
76
     */
77
    protected function createStreamHandler()
78
    {
79
        $streamHandler = new StreamHandler(
80
            Config::get(LogConstants::LOG_FILE_PATH),
81
            Config::get(LogConstants::LOG_LEVEL, Logger::INFO),
82
        );
83
        $formatter = new LogstashFormatter('Spryker');
84
        $streamHandler->setFormatter($formatter);
85
86
        return $streamHandler;
87
    }
88
89
    /**
90
     * @return \Monolog\Handler\FilterHandler
91
     */
92
    protected function createExceptionHandler()
93
    {
94
        $lineFormatter = new LineFormatter();
95
        $lineFormatter->includeStacktraces(true);
96
97
        $streamHandler = new StreamHandler(Config::get(LogConstants::EXCEPTION_LOG_FILE_PATH));
98
        $streamHandler->setFormatter($lineFormatter);
99
100
        $filterHandler = new FilterHandler($streamHandler, Logger::ERROR);
101
102
        return $filterHandler;
103
    }
104
}
105