4
4
5
5
use Exception ;
6
6
use Illuminate \Foundation \Exceptions \Handler ;
7
+ use Psr \Log \LoggerInterface ;
7
8
8
9
class ExceptionHandler extends Handler
9
10
{
10
- private $ log ;
11
+ private $ logger ;
11
12
private $ timeStarted ;
12
13
private $ timeFinished ;
13
14
protected $ reservedMemory ;
14
15
15
- public function __construct ( )
16
+ public function initialize ( LoggerInterface $ logger )
16
17
{
17
- parent ::__construct (app ());
18
-
19
- $ this ->log = app ('log.iclogger ' );
18
+ $ this ->logger = $ logger ;
20
19
$ this ->registerShutdownFunction ();
21
20
}
22
21
@@ -36,7 +35,7 @@ public function report(Exception $e)
36
35
}
37
36
}
38
37
39
- $ this ->log ->error ($ e ->getMessage (), $ context );
38
+ $ this ->logger ->error ($ e ->getMessage (), $ context );
40
39
}
41
40
42
41
private function registerShutdownFunction ()
@@ -49,14 +48,14 @@ private function registerShutdownFunction()
49
48
50
49
$ this ->timeFinished = microtime (true );
51
50
$ executionTime = round ($ this ->timeFinished - $ this ->timeStarted , 3 );
52
- $ this ->log ->info ("Execution time: {$ executionTime } sec. " );
51
+ $ this ->logger ->info ("Execution time: {$ executionTime } sec. " );
53
52
54
53
$ memoryPeak = format_bytes (memory_get_peak_usage (true ));
55
- $ this ->log ->info ("Memory peak usage: {$ memoryPeak }. " );
54
+ $ this ->logger ->info ("Memory peak usage: {$ memoryPeak }. " );
56
55
57
- $ this ->log ->info ('%separator% ' );
56
+ $ this ->logger ->info ('%separator% ' );
58
57
59
- $ handlers = $ this ->log ->getHandlers ();
58
+ $ handlers = $ this ->logger ->getHandlers ();
60
59
foreach ($ handlers as $ handler ) {
61
60
$ handler ->close ();
62
61
}
0 commit comments