44
55use Exception ;
66use Illuminate \Foundation \Exceptions \Handler ;
7+ use Psr \Log \LoggerInterface ;
78
89class ExceptionHandler extends Handler
910{
10- private $ log ;
11+ private $ logger ;
1112 private $ timeStarted ;
1213 private $ timeFinished ;
1314 protected $ reservedMemory ;
1415
15- public function __construct ( )
16+ public function initialize ( LoggerInterface $ logger )
1617 {
17- parent ::__construct (app ());
18-
19- $ this ->log = app ('log.iclogger ' );
18+ $ this ->logger = $ logger ;
2019 $ this ->registerShutdownFunction ();
2120 }
2221
@@ -36,7 +35,7 @@ public function report(Exception $e)
3635 }
3736 }
3837
39- $ this ->log ->error ($ e ->getMessage (), $ context );
38+ $ this ->logger ->error ($ e ->getMessage (), $ context );
4039 }
4140
4241 private function registerShutdownFunction ()
@@ -49,14 +48,14 @@ private function registerShutdownFunction()
4948
5049 $ this ->timeFinished = microtime (true );
5150 $ executionTime = round ($ this ->timeFinished - $ this ->timeStarted , 3 );
52- $ this ->log ->info ("Execution time: {$ executionTime } sec. " );
51+ $ this ->logger ->info ("Execution time: {$ executionTime } sec. " );
5352
5453 $ memoryPeak = format_bytes (memory_get_peak_usage (true ));
55- $ this ->log ->info ("Memory peak usage: {$ memoryPeak }. " );
54+ $ this ->logger ->info ("Memory peak usage: {$ memoryPeak }. " );
5655
57- $ this ->log ->info ('%separator% ' );
56+ $ this ->logger ->info ('%separator% ' );
5857
59- $ handlers = $ this ->log ->getHandlers ();
58+ $ handlers = $ this ->logger ->getHandlers ();
6059 foreach ($ handlers as $ handler ) {
6160 $ handler ->close ();
6261 }
0 commit comments