Skip to content

Commit 57554a0

Browse files
committed
ICL: Refactored shutdown handling.
1 parent 34e11ef commit 57554a0

File tree

3 files changed

+21
-31
lines changed

3 files changed

+21
-31
lines changed

src/Log/ErrorHandler.php

-28
This file was deleted.

src/Log/ExceptionHandler.php

+21
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
class ExceptionHandler extends Handler
99
{
10+
private $reservedMemory;
11+
1012
public function __construct()
1113
{
14+
$this->registerShutdownFunction();
15+
1216
parent::__construct(app('log.icl'));
1317
}
1418

@@ -21,4 +25,21 @@ public function report(Exception $e)
2125
'line' => $e->getLine(),
2226
]);
2327
}
28+
29+
private function registerShutdownFunction()
30+
{
31+
$this->reservedMemory = str_repeat(' ', 20 * 1024);
32+
33+
register_shutdown_function(function () {
34+
$this->reservedMemory = null;
35+
36+
$this->log->info('Execution time: trash.');
37+
$this->log->info('Memory peak usage: trash.');
38+
39+
$handlers = $this->log->getHandlers();
40+
foreach ($handlers as $handler) {
41+
$handler->close();
42+
}
43+
});
44+
}
2445
}

src/Loggable.php

-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
66
use Illuminate\Support\Str;
7-
use Illuminated\Console\Log\ErrorHandler;
87
use Illuminated\Console\Log\ExceptionHandler;
98
use Illuminated\Console\Log\Formatter;
109
use Monolog\Handler\RotatingFileHandler;
@@ -50,8 +49,6 @@ private function initializeErrorHandling()
5049
});
5150
$this->icl = app('log.icl');
5251

53-
ErrorHandler::registerIcl();
54-
5552
app()->singleton(ExceptionHandlerContract::class, ExceptionHandler::class);
5653
}
5754

0 commit comments

Comments
 (0)