Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
logger.php
1<?php
2
3namespace Bitrix\Sale\Cashbox;
4
9
14class Logger
15{
16 /* trace levels */
17 protected const TRACE_LEVEL_ERROR = 1;
18 protected const TRACE_LEVEL_WARNING = 2;
19 protected const TRACE_LEVEL_DEBUG = 3;
20
25 public static function addError(?string $message, $cashboxId = null): void
26 {
27 self::addToLog($message, $cashboxId, static::TRACE_LEVEL_ERROR);
28 }
29
34 public static function addWarning(?string $message, $cashboxId = null): void
35 {
36 self::addToLog($message, $cashboxId, static::TRACE_LEVEL_WARNING);
37 }
38
43 public static function addDebugInfo(?string $message, $cashboxId = null): void
44 {
45 self::addToLog($message, $cashboxId, static::TRACE_LEVEL_DEBUG);
46 }
47
52 private static function validateMessage(?string $message): bool
53 {
54 return !empty($message);
55 }
56
61 private static function checkMessageLevel(int $messageLevel): bool
62 {
63 return $messageLevel <= self::getLevel();
64 }
65
71 private static function addToLog(?string $message, $cashboxId, $messageLevel): void
72 {
73 if (self::checkMessageLevel($messageLevel) && self::validateMessage($message))
74 {
75 $data = [
76 'CASHBOX_ID' => $cashboxId,
77 'MESSAGE' => $message,
78 'DATE_INSERT' => new DateTime()
79 ];
80
81 CashboxErrLogTable::add($data);
82 }
83 }
84
90 private static function getLevel(): int
91 {
92 return (int)Option::get('sale', 'cashbox_log_level', static::TRACE_LEVEL_ERROR);
93 }
94}
static addDebugInfo(?string $message, $cashboxId=null)
Definition logger.php:43
static addWarning(?string $message, $cashboxId=null)
Definition logger.php:34
static addError(?string $message, $cashboxId=null)
Definition logger.php:25