Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 50c4d69

Browse files
committed
Логирование в файлы вынесено в отдельные методы
1 parent 3b42e75 commit 50c4d69

File tree

4 files changed

+59
-43
lines changed

4 files changed

+59
-43
lines changed

initializer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333
/*
3434
* code - отображать дебаг-данные в коде
3535
* debug_bar - отображать дебаг-данные в debug_bar
36-
* log - отображать дебаг-данные в логе
3736
*/
38-
$GD->setShowModes(['code', 'debug_bar', 'log']);
37+
$GD->setShowModes(['code', 'debug_bar']);
3938

4039
global $USER;
4140

@@ -52,5 +51,11 @@
5251
* $GD->warning('Моя переменная', 'Моя переменная 2');
5352
* $GD->success('Моя переменная', 'Моя переменная 2');
5453
*
54+
* Залогировать в файлы
55+
* $GD->noticeLog("Моя переменная', 'Моя переменная 2');
56+
* $GD->errorLog('Моя переменная', 'Моя переменная 2');
57+
* $GD->warningLog('Моя переменная', 'Моя переменная 2');
58+
* $GD->successLog('Моя переменная', 'Моя переменная 2');
59+
*
5560
*/
5661
include 'inizializer_alias.php';

src/BitrixDebugger/Debugger/Debugger.php

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,56 @@ public function warning(...$item) {
7878
public function success(...$item) {
7979
$this->noticeRaw('success', $item);
8080
}
81-
81+
82+
public function noticeLog(...$item) {
83+
$this->logRaw('notice', $item);
84+
}
85+
86+
public function errorLog(...$item) {
87+
$this->logRaw('error', $item);
88+
}
89+
90+
public function warningLog(...$item) {
91+
$this->logRaw('warning', $item);
92+
}
93+
94+
public function successLog(...$item) {
95+
$this->logRaw('success', $item);
96+
}
97+
98+
public function logRaw($type, ...$item) {
99+
100+
if (empty($item)) {
101+
return;
102+
}
103+
104+
$pathLogFile = $this->configuratorDebugger->getLogPath($type);
105+
106+
if ($pathLogFile) {
107+
$keyCache = $type . '_log_file_descriptor';
108+
109+
$fileLogDescriptor = null;
110+
111+
if (RuntimeCache::has($keyCache)) {
112+
$fileLogDescriptor = RuntimeCache::get($keyCache);
113+
} else {
114+
$fileLogDescriptor = \fopen($pathLogFile, 'a+');
115+
RuntimeCache::set($keyCache, $fileLogDescriptor);
116+
}
117+
118+
if ($fileLogDescriptor) {
119+
foreach ($item as $logItem) {
120+
// @todo возможность вывести через var_dump, var_export
121+
FileWriter::write(
122+
print_r($logItem, true),
123+
$fileLogDescriptor,
124+
$this->configuratorDebugger->getLogChunkDelimeter()
125+
);
126+
}
127+
}
128+
}
129+
}
130+
82131
public function getLog(): array {
83132
return $this->log;
84133
}
@@ -102,39 +151,6 @@ protected function noticeRaw(string $type, $arLogItems) {
102151
if (ShowModeDebuggerValidator::needShowInCode($this)) {
103152

104153
}
105-
106-
if (ShowModeDebuggerValidator::needWriteInLog($this)) {
107-
108-
if (empty($arLogItems)) {
109-
return;
110-
}
111-
112-
$pathLogFile = $this->configuratorDebugger->getLogPath($type);
113-
114-
if ($pathLogFile) {
115-
$keyCache = $type . '_log_file_descriptor';
116-
117-
$fileLogDescriptor = null;
118-
119-
if (RuntimeCache::has($keyCache)) {
120-
$fileLogDescriptor = RuntimeCache::get($keyCache);
121-
} else {
122-
$fileLogDescriptor = \fopen($pathLogFile, 'a+');
123-
RuntimeCache::set($keyCache, $fileLogDescriptor);
124-
}
125-
126-
if ($fileLogDescriptor) {
127-
foreach ($arLogItems as $logItem) {
128-
// @todo возможность вывести через var_dump, var_export
129-
FileWriter::write(
130-
print_r($logItem, true),
131-
$fileLogDescriptor,
132-
$this->configuratorDebugger->getLogChunkDelimeter()
133-
);
134-
}
135-
}
136-
}
137-
}
138154
}
139155

140156
}

src/BitrixDebugger/Debugger/DebuggerShowModable.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class DebuggerShowModable implements ShowModableContract {
2020
*
2121
* code - в коде
2222
* debug_bar - в дебаг-баре
23-
* log - в логе
2423
*
2524
* @var array
2625
*/
@@ -31,7 +30,7 @@ public function getShowModes(): array {
3130
}
3231

3332
public function getShowModesEnum(): array {
34-
return ['code', 'debug_bar', 'log'];
33+
return ['code', 'debug_bar'];
3534
}
3635

3736
public function setShowModes(array $showModes): bool {

src/BitrixDebugger/Validator/ShowModeDebuggerValidator.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,5 @@ public static function needShowInDebugBar(ShowModableContract $debugger) {
1818
public static function needShowInCode(ShowModableContract $debugger) {
1919
return in_array('code', $debugger->getShowModes());
2020
}
21-
22-
public static function needWriteInLog(ShowModableContract $debugger) {
23-
return in_array('log', $debugger->getShowModes());
24-
}
25-
21+
2622
}

0 commit comments

Comments
 (0)