Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
logger.php
1<?php
2
4
5use \Bitrix\Main\SystemException;
6
12class Logger
13{
15 const LOG_LEVEL_ERROR = 10;
16 const LOG_LEVEL_INFO = 20;
17 const LOG_LEVEL_DEBUG = 30;
18
19 protected $logLevel = self::LOG_LEVEL_ERROR;
20 protected $severities = array();
21
26 public function __construct($logLevel = self::LOG_LEVEL_ERROR)
27 {
28 $this->setLevel($logLevel);
29
30 $this->severities = array(
31 self::LOG_LEVEL_ERROR => "ERROR",
32 self::LOG_LEVEL_INFO => "INFO",
33 self::LOG_LEVEL_DEBUG => "DEBUG"
34 );
35 }
36
45 public function addRecord($level, $type, $itemId, $description)
46 {
47 if($this->logLevel < $level || $level == static::LOG_LEVEL_DISABLE)
48 return false;
49
50 if(!array_key_exists($level, $this->severities))
51 throw new SystemException("Unknown type of severity: ".$level.". ".__METHOD__);
52
53 $eventLog = new \CEventLog;
54
55 return $eventLog->Add(array(
56 "SEVERITY" => $this->severities[$level],
57 "AUDIT_TYPE_ID" => $type,
58 "MODULE_ID" => "sale",
59 "ITEM_ID" => $itemId,
60 "DESCRIPTION" => $description,
61 ));
62 }
63
68 public function setLevel($logLevel)
69 {
70 $this->logLevel = $logLevel;
71 }
72}
setLevel(string $level)
Definition logger.php:93
__construct($logLevel=self::LOG_LEVEL_ERROR)
Definition logger.php:26
addRecord($level, $type, $itemId, $description)
Definition logger.php:45