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

Commit adfd932

Browse files
committed
Сделан рабочий initializer.php под логирование в файлы
1 parent f7db2f9 commit adfd932

File tree

7 files changed

+32
-27
lines changed

7 files changed

+32
-27
lines changed

initializer.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44

55
use Bitrix\Main\Loader;
66

7+
$ggrachDebuggerRootPath = str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__);
8+
79
Loader::registerAutoLoadClasses(null, [
8-
"\GGrach\BitrixDebugger\Debugger\Debugger" => __DIR__ . "/src/BitrixDebugger/Debugger/Debugger.php",
9-
"\GGrach\BitrixDebugger\Debugger\DebuggerShowModable" => __DIR__ . "/src/BitrixDebugger/Debugger/DebuggerShowModable.php",
10-
"\GGrach\BitrixDebugger\Contract\ShowModableContract" => __DIR__ . "/src/BitrixDebugger/Contract/ShowModableContract.php",
11-
"\GGrach\BitrixDebugger\Configurator\DebuggerConfigurator" => __DIR__ . "/src/BitrixDebugger/Configurator/DebuggerConfigurator.php",
12-
"\GGrach\BitrixDebugger\Configurator\DebugBarConfigurator" => __DIR__ . "/src/BitrixDebugger/Configurator/DebugBarConfigurator.php",
13-
"\GGrach\BitrixDebugger\Cache\RuntimeCache" => __DIR__ . "/src/BitrixDebugger/Cache/RuntimeCache.php",
14-
"\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator" => __DIR__ . "/src/BitrixDebugger/Validator/ShowModeDebuggerValidator.php",
15-
"\GGrach\Writer\FileWriter" => __DIR__ . "/src/Writer/FileWriter.php",
16-
"\GGrach\Writer\Contract\WritableContract" => __DIR__ . "/src/Writer/Contract/WritableContract.php"
10+
"\GGrach\BitrixDebugger\Debugger\Debugger" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Debugger/Debugger.php",
11+
"\GGrach\BitrixDebugger\Debugger\DebuggerShowModable" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Debugger/DebuggerShowModable.php",
12+
"\GGrach\BitrixDebugger\Contract\ShowModableContract" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Contract/ShowModableContract.php",
13+
"\GGrach\BitrixDebugger\Configurator\DebuggerConfigurator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Configurator/DebuggerConfigurator.php",
14+
"\GGrach\BitrixDebugger\Configurator\DebugBarConfigurator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Configurator/DebugBarConfigurator.php",
15+
"\GGrach\BitrixDebugger\Cache\RuntimeCache" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Cache/RuntimeCache.php",
16+
"\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Validator/ShowModeDebuggerValidator.php",
17+
"\GGrach\Writer\FileWriter" => $ggrachDebuggerRootPath . "/src/Writer/FileWriter.php",
18+
"\GGrach\Writer\Contract\WritableContract" => $ggrachDebuggerRootPath . "/src/Writer/Contract/WritableContract.php"
1719
]);
1820

1921
$ggrachDebuggerConfigurator = new \GGrach\BitrixDebugger\Configurator\DebuggerConfigurator();
@@ -24,7 +26,14 @@
2426
$ggrachDebuggerConfigurator->setLogPath('success', __DIR__ . '/logs/success.log');
2527
$ggrachDebuggerConfigurator->setLogPath('notice', __DIR__ . '/logs/notice.log');
2628

29+
/*
30+
* code - отображать дебаг-данные в коде
31+
* debug_bar - отображать дебаг-данные в debug_bar
32+
* log - отображать дебаг-данные в логе
33+
*/
34+
$ggrachDebuggerConfigurator->setShowModes(['code', 'debug_bar', 'log']);
35+
2736
global $GD;
2837
$GD = new \GGrach\BitrixDebugger\Debugger\Debugger($ggrachDebuggerConfigurator, $ggrachDebugBarConfigurator);
2938

30-
include 'inizializer_alias.php';
39+
include 'inizializer_alias.php';

logs/.gitkeep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/BitrixDebugger/Configurator/DebuggerConfigurator.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@ class DebuggerConfigurator {
2626
*
2727
* @var string
2828
*/
29-
protected $logChunkDelimeter = "======\n";
29+
protected $logChunkDelimeter = "\n======\n";
3030

3131
public function setLogPath(string $logType, string $pathFile): self {
32-
if (\array_key_exists($logType, $this->getLogPaths())) {
33-
$this->logPaths[$logType] = $pathFile;
34-
}
35-
32+
$this->logPaths[$logType] = $pathFile;
3633
return $this;
3734
}
3835

@@ -68,10 +65,4 @@ public function setLogChunkDelimeter(string $logChunkDelimeter): self {
6865
return $this;
6966
}
7067

71-
public function addLogType(string $keyLog, string $pathLogFile): self {
72-
$this->logPaths[$keyLog] = $pathLogFile;
73-
74-
return $this;
75-
}
76-
7768
}

src/BitrixDebugger/Debugger/Debugger.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @author ggrachdev
1717
* @version 0.01
1818
*/
19-
class Debugger extends DebuggerShowModable implements ShowModableContract {
19+
class Debugger extends DebuggerShowModable {
2020

2121
/**
2222
*
@@ -67,6 +67,10 @@ public function notice(...$item) {
6767
$this->noticeRaw('notice', $item);
6868
}
6969

70+
public function error(...$item) {
71+
$this->noticeRaw('error', $item);
72+
}
73+
7074
public function warning(...$item) {
7175
$this->noticeRaw('warning', $item);
7276
}

src/BitrixDebugger/Debugger/DebuggerShowModable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DebuggerShowModable implements ShowModableContract {
2626
*/
2727
protected $showModes = ['code', 'debug_bar'];
2828

29-
public function getShowModes() {
29+
public function getShowModes(): array {
3030
return $this->showModes;
3131
}
3232

src/Writer/Contract/WritableContract.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ interface WritableContract {
1616
* @param resource $resource
1717
* @param string $delimeter
1818
*/
19-
public static function write(string $text, resource $resource, string $delimeter): bool;
19+
public static function write(string $text, $resource, string $delimeter): bool;
2020

2121
/**
2222
* Очистка данных
2323
*
2424
* @param resource $resource
2525
*/
26-
public static function clear(resource $resource): bool;
26+
public static function clear($resource): bool;
2727
}

src/Writer/FileWriter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FileWriter implements WritableContract {
1818
* @param resource $resource
1919
* @param string $delimeter
2020
*/
21-
public static function write(string $text, resource $resource, string $delimeter): bool {
21+
public static function write(string $text, $resource, string $delimeter): bool {
2222
return fwrite($resource, $text . $delimeter) !== false;
2323
}
2424

@@ -27,7 +27,7 @@ public static function write(string $text, resource $resource, string $delimeter
2727
*
2828
* @param resource $resource
2929
*/
30-
public static function clear(resource $resource): bool {
30+
public static function clear($resource): bool {
3131

3232
$arMetaData = \stream_get_meta_data($resource);
3333
$pathFile = $arMetaData['uri'];

0 commit comments

Comments
 (0)