-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMonologConfiguration.php
More file actions
141 lines (120 loc) · 3.9 KB
/
Copy pathMonologConfiguration.php
File metadata and controls
141 lines (120 loc) · 3.9 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\OxLogIQ;
use D3\OxLogIQ\Interfaces\MonologConfigurationInterface as OxLogIQConfigurationInterface;
use D3\OxLogIQ\Release\ReleaseServiceInterface;
use InvalidArgumentException;
use Monolog\Logger;
use OxidEsales\Eshop\Application\Model\Shop;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Logger\Configuration\MonologConfigurationInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class MonologConfiguration implements MonologConfigurationInterface, OxLogIQConfigurationInterface
{
/**
* @param \OxidEsales\EshopCommunity\Internal\Framework\Logger\Configuration\MonologConfiguration $innerConfig
* @param \OxidEsales\EshopCommunity\Core\Config $config
* @param Context $context
*/
public function __construct(
protected MonologConfigurationInterface $innerConfig,
protected Config $config,
protected ContextInterface $context
) {
}
public function getLoggerName(): string
{
/** @var Shop $shop */
$shop = $this->config->getActiveShop();
return implode(
'|',
[
$this->innerConfig->getLoggerName(),
'shp-'.$shop->getId(),
$this->getContext(),
]
);
}
/**
* @codeCoverageIgnore
*/
protected function getContext(): string
{
return isAdmin() ? 'backend' : 'frontend'; // @phpstan-ignore function.notFound
}
public function getLogFilePath(): string
{
return $this->innerConfig->getLogFilePath();
}
public function getLogLevel(): string
{
// is already validated
return $this->innerConfig->getLogLevel();
}
public function getRetentionDays(): ?int
{
return $this->context->getRetentionDays();
}
public function useAlertMail(): bool
{
return $this->context->useAlertMail() && $this->hasAlertMailRecipient();
}
public function hasAlertMailRecipient(): bool
{
$recipients = $this->getAlertMailRecipients();
return is_array($recipients) && count($recipients) > 0;
}
/**
* @return string[]|null
*/
public function getAlertMailRecipients(): ?array
{
return $this->context->getAlertMailRecipients();
}
/**
* @throws InvalidArgumentException
*/
public function getAlertMailLevel(): string
{
$level = strtoupper($this->context->getAlertMailLevel());
if (!in_array($level, array_keys(Logger::getLevels()), true)) {
throw new InvalidArgumentException(
'Mail alerting level must be one of '.implode(', ', array_keys(Logger::getLevels()))
);
}
return $level;
}
public function getAlertMailSubject(): string
{
return $this->context->getAlertMailSubject();
}
public function getAlertMailFrom(): ?string
{
return $this->context->getAlertMailFrom();
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getRelease(): string
{
/** @var ReleaseServiceInterface $service */
$service = ContainerFactory::getInstance()->getContainer()->get(ReleaseServiceInterface::class);
return $service->getRelease();
}
}