-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLoggingConfiguration.php
70 lines (61 loc) · 1.83 KB
/
LoggingConfiguration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
namespace Core\Logger\Configuration;
use Core\Logger\ConsoleLogger;
use Psr\Log\LoggerInterface;
class LoggingConfiguration
{
private $logger;
private $level;
private $maskSensitiveHeaders;
private $requestConfig;
private $responseConfig;
public function __construct(
?LoggerInterface $logger,
string $level,
bool $maskSensitiveHeaders,
RequestConfiguration $requestConfig,
ResponseConfiguration $responseConfig
) {
$this->logger = $logger ?? new ConsoleLogger('printf');
$this->level = $level;
$this->maskSensitiveHeaders = $maskSensitiveHeaders;
$this->requestConfig = $requestConfig;
$this->responseConfig = $responseConfig;
}
/**
* Log the given message using the context array. This function uses the
* LogLevel and Logger instance set via constructor of this class.
*/
public function logMessage(string $message, array $context): void
{
$this->logger->log($this->level, $message, $context);
}
/**
* Indicates whether sensitive headers should be masked in logs.
*
* @return bool True if sensitive headers should be masked, false otherwise.
*/
public function shouldMaskSensitiveHeaders(): bool
{
return $this->maskSensitiveHeaders;
}
/**
* Gets the request configuration for logging.
*
* @return RequestConfiguration The request configuration.
*/
public function getRequestConfig(): RequestConfiguration
{
return $this->requestConfig;
}
/**
* Gets the response configuration for logging.
*
* @return ResponseConfiguration The response configuration.
*/
public function getResponseConfig(): ResponseConfiguration
{
return $this->responseConfig;
}
}