Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
loggerservice.php
1
<?php
2
3
namespace
Bitrix\Location\Infrastructure\Service
;
4
5
use
Bitrix\Location\Common\BaseService
;
6
use
Bitrix\Location\Infrastructure\Service\LoggerService\ILogger
;
7
use
Bitrix\Location\Infrastructure\Service\Config\Container
;
8
9
final
class
LoggerService
extends
BaseService
implements
ILogger
10
{
12
protected
static
$instance
;
13
15
private
$logger;
16
private
$logLevel;
17
private
$eventsToLog;
18
19
public
function
log
(
int
$level,
string
$message,
int
$eventType = 0, array $context = [])
20
{
21
if
(!$this->
isLevelSatisfied
($level) && !$this->
isEventSatisfied
($eventType))
22
{
23
return
;
24
}
25
26
if
(count($context) > 0)
27
{
28
$message = $this->interpolate($message, $context);
29
}
30
31
$this->logger->log($level, $message, $eventType, $context);
32
}
33
34
protected
function
isLevelSatisfied
(
int
$level): bool
35
{
36
return
$this->logLevel >= $level;
37
}
38
39
protected
function
isEventSatisfied
(
int
$eventType): bool
40
{
41
return
$eventType > 0 && in_array($eventType, $this->eventsToLog);
42
}
43
44
protected
function
__construct
(
Container
$config)
45
{
46
parent::__construct($config);
47
$loggerClass = $config->
get
(
'logger'
);
48
$this->logLevel = $config->
get
(
'logLevel'
);
49
$this->eventsToLog = $config->
get
(
'eventsToLog'
);
50
$this->logger =
new
$loggerClass();
51
}
52
53
private
function
interpolate($message, array $context = array())
54
{
55
$replace = [];
56
57
foreach
($context as $key => $val)
58
{
59
if
(!is_array($val) && (!is_object($val) || method_exists($val,
'__toString'
)))
60
{
61
$replace[
'{'
. $key .
'}'
] = $val;
62
}
63
}
64
65
return
strtr($message, $replace);
66
}
67
}
Bitrix\Location\Common\BaseService
Definition
baseservice.php:12
Bitrix\Location\Infrastructure\Service\Config\Container
Definition
container.php:8
Bitrix\Location\Infrastructure\Service\Config\Container\get
get($id)
Definition
container.php:16
Bitrix\Location\Infrastructure\Service\LoggerService
Definition
loggerservice.php:10
Bitrix\Location\Infrastructure\Service\LoggerService\log
log(int $level, string $message, int $eventType=0, array $context=[])
Definition
loggerservice.php:19
Bitrix\Location\Infrastructure\Service\LoggerService\__construct
__construct(Container $config)
Definition
loggerservice.php:44
Bitrix\Location\Infrastructure\Service\LoggerService\isLevelSatisfied
isLevelSatisfied(int $level)
Definition
loggerservice.php:34
Bitrix\Location\Infrastructure\Service\LoggerService\$instance
static $instance
Definition
loggerservice.php:12
Bitrix\Location\Infrastructure\Service\LoggerService\isEventSatisfied
isEventSatisfied(int $eventType)
Definition
loggerservice.php:39
Bitrix\Location\Infrastructure\Service\LoggerService\ILogger
Definition
ilogger.php:5
Bitrix\Location\Infrastructure\Service
modules
location
lib
infrastructure
service
loggerservice.php
Создано системой
1.10.0