Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
logger.php
1<?
3
9
10class Logger
11{
12 const TYPE_CACHE_REWRITING = "CACHE_REWRITING";
13 const TYPE_COMPONENT_VOTING = "COMPONENT_VOTING";
14 const TYPE_BUFFER_RESTART = "BUFFER_RESTART";
15 const TYPE_CACHE_RESET = "CACHE_RESET";
16
17 const TYPE_GET_METHOD_ONLY = "GET_METHOD_ONLY";
18 const TYPE_NCC_PARAMETER = "NCC_PARAMETER";
19 const TYPE_NCC_COOKIE = "NCC_COOKIE";
20 const TYPE_EXCLUDE_MASK = "EXCLUDE_MASK";
21 const TYPE_EXCLUDE_PARAMETER = "EXCLUDE_PARAMETER";
22 const TYPE_INCLUDE_MASK = "INCLUDE_MASK";
23 const TYPE_INVALID_HOST = "INVALID_HOST";
24 const TYPE_INVALID_QUERY_STRING = "INVALID_QUERY_STRING";
25
26 const TYPE_LOCAL_REDIRECT = "LOCAL_REDIRECT";
27 const TYPE_ADMIN_PANEL = "ADMIN_PANEL";
28 const TYPE_PHP_SHUTDOWN = "PHP_SHUTDOWN";
29 const TYPE_PAGE_NOT_CACHEABLE = "PAGE_NOT_CACHEABLE";
30 const TYPE_COMPOSITE_NOT_INJECTED = "COMPOSITE_NOT_INJECTED";
31
32 const TYPE_CC_COOKIE_NOT_FOUND = "CC_COOKIE_NOT_FOUND";
33 const TYPE_SESSID_PARAMETER = "SESSID_PARAMETER";
34 const TYPE_AJAX_REQUEST = "AJAX_REQUEST";
35 const TYPE_BITRIX_FOLDER = "BITRIX_FOLDER";
36 const TYPE_CONTROLLER_FILE = "CONTROLLER_FILE";
37 const TYPE_MESSAGE = "MESSAGE";
38
39 const END_TIME_OPTION = "composite_debug_end_time";
40
41 public static function isOn()
42 {
43 return time() < Option::get("main", static::END_TIME_OPTION, 0);
44 }
45
46 public static function enable($endTime = 0)
47 {
48 Option::set("main", static::END_TIME_OPTION, intval($endTime));
49 }
50
51 public static function disable()
52 {
53 Option::delete("main", array("name" => static::END_TIME_OPTION));
54 }
55
56 public static function getEndTime()
57 {
58 return intval(Option::get("main", static::END_TIME_OPTION, 0));
59 }
60
61 public static function log(array $params = array())
62 {
63 if (!static::isOn())
64 {
65 return null;
66 }
67
68 $pageTitle = $params["TITLE"] ?? $GLOBALS["APPLICATION"]->getTitle();
69 $pageTitle = mb_substr($pageTitle, 0, 250);
70
71 $pageHost = isset($params["HOST"]) && mb_strlen($params["HOST"]) ? $params["HOST"] : Helper::getHttpHost();
72 $pageHost = mb_substr($pageHost, 0, 100);
73
74 $pageUri = isset($params["URI"]) && mb_strlen($params["URI"]) ? $params["URI"] : Helper::getRequestUri();
75 $pageUri = mb_substr($pageUri, 0, 2000);
76
77 $userId = 0;
78 if (isset($params["USER_ID"]))
79 {
80 $userId = intval($params["USER_ID"]);
81 }
82 else if (isset($GLOBALS["USER"]) && $GLOBALS["USER"]->isAuthorized())
83 {
84 $userId = intval($GLOBALS["USER"]->getId());
85 }
86
87 $data = array(
88 "TITLE" => $pageTitle,
89 "MESSAGE" => isset($params["MESSAGE"]) && is_string($params["MESSAGE"]) ? $params["MESSAGE"] : null,
90 "TYPE" =>
91 isset($params["TYPE"]) && in_array($params["TYPE"], self::getTypes())
92 ? $params["TYPE"]
94 "URI" => $pageUri,
95 "HOST" => $pageHost,
96 "USER_ID" => $userId,
97 "AJAX" => Engine::isAjaxRequest() ? "Y" : "N",
98 "PAGE_ID" => isset($params["PAGE_ID"]) ? intval($params["PAGE_ID"]) : 0
99 );
100
101 $GLOBALS["DB"]->StartUsingMasterOnly();
102
103 $result = LogTable::add($data);
104
105 $GLOBALS["DB"]->StopUsingMasterOnly();
106
107 return $result;
108 }
109
114 public static function getTypes()
115 {
116 static $types = null;
117 if ($types !== null)
118 {
119 return $types;
120 }
121
122 $types = array();
123 $refClass = new \ReflectionClass(__CLASS__);
124 foreach ($refClass->getConstants() as $name => $value)
125 {
126 if (mb_substr($name, 0, 4) === "TYPE")
127 {
128 $types[] = $value;
129 }
130 }
131
132 return $types;
133 }
134
140 public static function getTypeName($type)
141 {
142 static $messagesLoaded = false;
143
144 if (!$messagesLoaded)
145 {
146 Loc::loadMessages(__FILE__);
147 $messagesLoaded = true;
148 }
149
150 $types = static::getTypes();
151 if (!in_array($type, $types))
152 {
153 return null;
154 }
155
156 return Loc::getMessage("MAIN_COMPOSITE_LOG_{$type}") ?: $type;
157 }
158}
static enable($endTime=0)
Definition logger.php:46
static log(array $params=array())
Definition logger.php:61
static getHttpHost($host=null)
Definition helper.php:41
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
$GLOBALS['____1444769544']
Definition license.php:1