Skip to content

Commit 86ce56b

Browse files
committed
ICL: Custom error handler added.
1 parent 12cda93 commit 86ce56b

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/Log/ErrorHandler.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Illuminated\Console\Log;
4+
5+
use Monolog\ErrorHandler as MonologErrorHandler;
6+
7+
class ErrorHandler extends MonologErrorHandler
8+
{
9+
public static function registerIcl()
10+
{
11+
$handler = new static(app('log.icl'));
12+
$handler->registerErrorHandler();
13+
$handler->registerFatalHandler();
14+
15+
return $handler;
16+
}
17+
18+
public function handleFatalError()
19+
{
20+
$logger = app('log.icl');
21+
22+
$logger->info('Execution time: trash.');
23+
$logger->info('Memory peak usage: trash.');
24+
25+
foreach ($logger->getHandlers() as $handler) {
26+
$handler->close();
27+
}
28+
}
29+
}

src/Loggable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
66
use Illuminate\Support\Str;
7+
use Illuminated\Console\Log\ErrorHandler;
78
use Illuminated\Console\Log\ExceptionHandler;
89
use Illuminated\Console\Log\Formatter;
9-
use Monolog\ErrorHandler;
1010
use Monolog\Handler\RotatingFileHandler;
1111
use Monolog\Logger;
1212
use Symfony\Component\Console\Input\InputInterface;
@@ -50,7 +50,7 @@ private function initializeErrorHandling()
5050
});
5151
$this->icl = app('log.icl');
5252

53-
ErrorHandler::register($this->icl);
53+
ErrorHandler::registerIcl();
5454

5555
app()->singleton(ExceptionHandlerContract::class, ExceptionHandler::class);
5656
}

0 commit comments

Comments
 (0)