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), |
|
|
|
|
66
|
|
|
new EnvironmentProcessor(), |
|
|
|
|
67
|
|
|
new ServerProcessor(), |
|
|
|
|
68
|
|
|
new RequestProcessor($sanitizer), |
|
|
|
|
69
|
|
|
new ResponseProcessor(), |
|
|
|
|
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
|
|
|
|