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

Commit 1942d13

Browse files
committed
Исправлены ошибки с количеством логов
1 parent 50264e7 commit 1942d13

File tree

6 files changed

+160
-125
lines changed

6 files changed

+160
-125
lines changed

assets/DebugBar/themes/general.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
z-index: 9998;
1919
}
2020

21+
.ggrach__debug_bar__item {
22+
-webkit-touch-callout: none; /* iOS Safari */
23+
-webkit-user-select: none; /* Chrome/Safari/Opera */
24+
-khtml-user-select: none; /* Konqueror */
25+
-moz-user-select: none; /* Firefox */
26+
-ms-user-select: none; /* Internet Explorer/Edge */
27+
user-select: none; /* Non-prefixed version, currently
28+
not supported by any browser */
29+
}
30+
2131
.ggrach__debug_bar > .ggrach__debug_bar__item {
2232
display: flex !important;
2333
line-height: 33px !important;

functions.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
/**
4+
* Красивая подстветка дебага
5+
*
6+
* @param type $data
7+
* @return type
8+
*/
9+
function ggrach_highlight_data($data = []) {
10+
11+
$viewResult = '';
12+
13+
$need_hide_blocks = true;
14+
15+
$ppr = function ($in, $opened, $margin = 5) use(&$ppr, $need_hide_blocks) {
16+
17+
$viewRes = '';
18+
19+
if (!\is_object($in) && !\is_array($in)) {
20+
return $in;
21+
}
22+
23+
if ($need_hide_blocks == true)
24+
$opened = '';
25+
26+
foreach ($in as $key => $value) {
27+
if (\is_object($value) || \is_array($value)) {
28+
$viewRes .= '<details style="margin-left:' . $margin . 'px" ' . $opened . '>';
29+
$viewRes .= '<summary style="cursor: pointer; margin-top: 5px; margin-bottom: 5px; text-decoration: underline;">';
30+
$viewRes .= (is_object($value)) ? $key . ' {' . count((array) $value) . '}' : $key . ' [' . count($value) . ']';
31+
$viewRes .= '</summary>';
32+
$viewRes .= $ppr($value, $opened, $margin + 5);
33+
$viewRes .= '</details>';
34+
} else {
35+
switch (gettype($value)) {
36+
case 'string':
37+
$bgc = 'red';
38+
$value = \strip_tags($value);
39+
if (\strlen($value) > 200) {
40+
$value = '[Очень длинная строка]';
41+
}
42+
43+
break;
44+
case 'integer':
45+
$bgc = 'green';
46+
break;
47+
}
48+
$viewRes .= '<div style="margin-left:' . $margin . 'px">' . $key . ' : <span style="color:' . $bgc . '">' . $value . '</span> <span style="color: blue;">(' . gettype($value) . ')</span></div>';
49+
}
50+
}
51+
52+
return $viewRes;
53+
};
54+
55+
$pp = function ($in, $opened = true) use ($ppr) {
56+
57+
$view = '';
58+
59+
if ($opened) {
60+
$opened = ' open';
61+
}
62+
63+
64+
$view .= '<div>';
65+
66+
if (is_object($in) or is_array($in)) {
67+
$view .= '<details' . $opened . '>';
68+
$view .= '<summary style="cursor: pointer; margin-top: 5px; margin-bottom: 5px; text-decoration: underline;">';
69+
$view .= (is_object($in)) ? 'Object {' . count((array) $in) . '}' : 'Array [' . count($in) . ']';
70+
$view .= '</summary>';
71+
$view .= $ppr($in, $opened);
72+
$view .= '</details>';
73+
} else {
74+
switch (gettype($in)) {
75+
case 'string':
76+
$bgc = 'red';
77+
78+
$in = \strip_tags($in);
79+
80+
if (\strlen($in) > 200) {
81+
$in = '[Очень длинная строка]';
82+
}
83+
84+
break;
85+
case 'integer':
86+
$bgc = 'green';
87+
break;
88+
}
89+
90+
$view .= '<div style="margin-left: 0px"><span style="color:' . $bgc . '">' . $in . '</span> <span style="color: blue;">(' . gettype($in) . ')</span></div>';
91+
}
92+
93+
94+
$view .= '</div>';
95+
96+
97+
return $view;
98+
};
99+
100+
$viewResult .= $pp($data, !$need_hide_blocks);
101+
102+
return $viewResult;
103+
}

initializer.php

Lines changed: 18 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
<?php
22

3-
// Need include this file in init.php
3+
// Нужно подключить этот файл в init.php
44
// include 'BitrixDebugger/initializer.php';
55

6+
/**
7+
* Пример дебага:
8+
*
9+
* GD()->notice('Моя переменная', 'Моя переменная 2');
10+
* GD()->error('Моя переменная', 'Моя переменная 2');
11+
* GD()->warning('Моя переменная', 'Моя переменная 2');
12+
* GD()->success('Моя переменная', 'Моя переменная 2');
13+
*
14+
* Залогировать в файлы
15+
* GD()->noticeLog('Моя переменная', 'Моя переменная 2');
16+
* GD()->errorLog('Моя переменная', 'Моя переменная 2');
17+
* GD()->warningLog('Моя переменная', 'Моя переменная 2');
18+
* GD()->successLog('Моя переменная', 'Моя переменная 2');
19+
*
20+
*/
21+
622
use Bitrix\Main\Loader;
723
use Bitrix\Main\Page\Asset;
824

@@ -47,118 +63,9 @@ function GD() {
4763
Asset::getInstance()->addCss($ggrachDebuggerRootPath . '/assets/DebugBar/themes/general.css');
4864
Asset::getInstance()->addCss($ggrachDebuggerRootPath . '/assets/DebugBar/themes/' . $ggrachDebugBarConfigurator->getColorTheme() . '/theme.css');
4965

50-
/**
51-
* Пример дебага:
52-
*
53-
* GD()->notice('Моя переменная', 'Моя переменная 2');
54-
* GD()->error('Моя переменная', 'Моя переменная 2');
55-
* GD()->warning('Моя переменная', 'Моя переменная 2');
56-
* GD()->success('Моя переменная', 'Моя переменная 2');
57-
*
58-
* Залогировать в файлы
59-
* GD()->noticeLog('Моя переменная', 'Моя переменная 2');
60-
* GD()->errorLog('Моя переменная', 'Моя переменная 2');
61-
* GD()->warningLog('Моя переменная', 'Моя переменная 2');
62-
* GD()->successLog('Моя переменная', 'Моя переменная 2');
63-
*
64-
*/
65-
include 'inizializer_alias.php';
66-
6766
if (\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator::needShowInDebugBar($GD)) {
6867

69-
function ggrach_highlight_data($data = []) {
70-
71-
$viewResult = '';
72-
73-
$need_hide_blocks = true;
74-
75-
$ppr = function ($in, $opened, $margin = 5) use(&$ppr, $need_hide_blocks) {
76-
77-
$viewRes = '';
78-
79-
if (!\is_object($in) && !\is_array($in)) {
80-
return $in;
81-
}
82-
83-
if ($need_hide_blocks == true)
84-
$opened = '';
85-
86-
foreach ($in as $key => $value) {
87-
if (\is_object($value) || \is_array($value)) {
88-
$viewRes .= '<details style="margin-left:' . $margin . 'px" ' . $opened . '>';
89-
$viewRes .= '<summary style="cursor: pointer; margin-top: 5px; margin-bottom: 5px; text-decoration: underline;">';
90-
$viewRes .= (is_object($value)) ? $key . ' {' . count((array) $value) . '}' : $key . ' [' . count($value) . ']';
91-
$viewRes .= '</summary>';
92-
$viewRes .= $ppr($value, $opened, $margin + 5);
93-
$viewRes .= '</details>';
94-
} else {
95-
switch (gettype($value)) {
96-
case 'string':
97-
$bgc = 'red';
98-
99-
if (\strlen($value) > 500) {
100-
$value = '[Очень длинная строка]';
101-
}
102-
103-
break;
104-
case 'integer':
105-
$bgc = 'green';
106-
break;
107-
}
108-
$viewRes .= '<div style="margin-left:' . $margin . 'px">' . $key . ' : <span style="color:' . $bgc . '">' . $value . '</span> <span style="color: blue;">(' . gettype($value) . ')</span></div>';
109-
}
110-
}
111-
112-
return $viewRes;
113-
};
114-
115-
$pp = function ($in, $opened = true) use ($ppr) {
116-
117-
$view = '';
118-
119-
if ($opened) {
120-
$opened = ' open';
121-
}
122-
123-
124-
$view .= '<div>';
125-
126-
if (is_object($in) or is_array($in)) {
127-
$view .= '<details' . $opened . '>';
128-
$view .= '<summary style="cursor: pointer; margin-top: 5px; margin-bottom: 5px; text-decoration: underline;">';
129-
$view .= (is_object($in)) ? 'Object {' . count((array) $in) . '}' : 'Array [' . count($in) . ']';
130-
$view .= '</summary>';
131-
$view .= $ppr($in, $opened);
132-
$view .= '</details>';
133-
} else {
134-
switch (gettype($in)) {
135-
case 'string':
136-
$bgc = 'red';
137-
138-
if (\strlen($in) > 500) {
139-
$in = '[Очень длинная строка]';
140-
}
141-
142-
break;
143-
case 'integer':
144-
$bgc = 'green';
145-
break;
146-
}
147-
148-
$view .= '<div style="margin-left: 0px"><span style="color:' . $bgc . '">' . $in . '</span> <span style="color: blue;">(' . gettype($in) . ')</span></div>';
149-
}
150-
151-
152-
$view .= '</div>';
153-
154-
155-
return $view;
156-
};
157-
158-
$viewResult .= $pp($data, !$need_hide_blocks);
159-
160-
return $viewResult;
161-
}
68+
include 'functions.php';
16269

16370
include 'events.php';
16471
}

inizializer_alias.php

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/BitrixDebugger/Debugger/Debugger.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,18 @@ public function debug($typeNotice, ...$item) {
145145
protected function noticeRaw(string $type, $arLogItems) {
146146

147147
if (ShowModeDebuggerValidator::needShowInDebugBar($this)) {
148-
149-
if(!\array_key_exists($type, $this->getLog()))
150-
{
151-
$this->log[$type] = [];
148+
149+
if (!\array_key_exists($type, $this->getLog())) {
150+
$this->log[$type] = [];
152151
}
153-
154-
$this->log[$type] = array_merge($this->getLog()[$type], $arLogItems);
152+
153+
$db = debug_backtrace();
154+
155+
$this->log[$type][] = [
156+
'file' => $db[1]['file'],
157+
'line' => $db[1]['line'],
158+
'data' => $arLogItems
159+
];
155160
}
156161

157162
if (ShowModeDebuggerValidator::needShowInCode($this)) {

src/BitrixDebugger/Representer/DebugBarRepresenter.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,28 @@ public static function render(Debugger $debugger): string {
2323
if (!empty($log)) {
2424
foreach ($log as $typeLog => $arLogs) {
2525
$view .= '<div class="ggrach__debug_bar__item type-notice-' . $typeLog . '" data-type-notice="' . $typeLog . '" data-click="show_notice_panel">';
26-
$view .= \sizeof($arLogs['data']);
26+
27+
$count = 0;
28+
29+
foreach ($arLogs as $arLogType)
30+
{
31+
$count += \sizeof($arLogType['data']);
32+
}
33+
34+
$view .= $count;
2735
$view .= '</div>';
2836

2937
$view .= '<div class="ggrach__debug_bar__log" data-type-notice="' . $typeLog . '" style="display: none;">';
30-
foreach ($arLogs['data'] as $logValue) {
31-
32-
$lineView = '<a class="ggrach__debug_bar__log__line" target="_blank" href="/bitrix/admin/fileman_file_edit.php?path=' . str_replace($_SERVER['DOCUMENT_ROOT'], '', $arLogs['file']) . '&full_src=Y">' . $arLogs['file'] . ' on line ' . $arLogs['line'] . '</a>';
33-
34-
$view .= str_replace(['<span style="color: #0000BB">&lt;?</span>', '<span style="color: #0000BB">?&gt;</span>', '&lt;?', '?&gt;', '&lt;?php'], ['', '', '', ''], '<pre>' . \ggrach_highlight_data($logValue) . $lineView . '</pre>');
38+
39+
foreach ($arLogs as $arLogType) {
40+
41+
foreach ($arLogType['data'] as $logValue) {
42+
$lineView = '<a class="ggrach__debug_bar__log__line" target="_blank" href="/bitrix/admin/fileman_file_edit.php?path=' . str_replace($_SERVER['DOCUMENT_ROOT'], '', $arLogType['file']) . '&full_src=Y">' . $arLogType['file'] . ' on line ' . $arLogType['line'] . '</a>';
43+
44+
$view .= str_replace(['<span style="color: #0000BB">&lt;?</span>', '<span style="color: #0000BB">?&gt;</span>', '&lt;?', '?&gt;', '&lt;?php'], ['', '', '', ''], '<pre>'. \ggrach_highlight_data($logValue) . $lineView . '</pre>');
45+
}
3546
}
47+
3648
$view .= '</div>';
3749
}
3850
}

0 commit comments

Comments
 (0)