@@ -32,7 +32,11 @@ class TestCommand extends Command
32
32
}
33
33
34
34
/** @noinspection ClassOverridesFieldOfSuperClassInspection */
35
- protected $ signature = 'exception-notify:test {--c|channel= : The channel of report exception} ' ;
35
+ protected $ signature = <<<'SIGNATURE'
36
+ exception-notify:test
37
+ {--c|channel= : The channel of report exception}
38
+ {--queue-connection= : The queue connection of report exception}
39
+ SIGNATURE;
36
40
37
41
/** @noinspection ClassOverridesFieldOfSuperClassInspection */
38
42
protected $ description = 'Testing ' ;
@@ -43,17 +47,20 @@ class TestCommand extends Command
43
47
public function handle (ExceptionNotifyManager $ exceptionNotifyManager ): int
44
48
{
45
49
if (!config ($ configurationKey = 'exception-notify.enabled ' )) {
46
- $ this ->output ->warning ("The value of this configuration [ $ configurationKey] is false, please configure it to true. " );
50
+ $ this ->components ->warn (\sprintf (
51
+ 'The value of this configuration [%s] is false, please configure it to true. ' ,
52
+ $ this ->warned ($ configurationKey )
53
+ ));
47
54
48
55
return self ::INVALID ;
49
56
}
50
57
51
- $ runtimeException = new RuntimeException ('Testing ' );
58
+ $ runtimeException = new RuntimeException ('This is a test. ' );
52
59
53
60
if (!$ exceptionNotifyManager ->shouldReport ($ runtimeException )) {
54
- $ this ->output -> warning (\sprintf (
61
+ $ this ->components -> warn (\sprintf (
55
62
'The exception [%s] should not be reported, please check the configuration. ' ,
56
- $ runtimeException ::class
63
+ $ this -> warned ( $ runtimeException ::class),
57
64
));
58
65
59
66
return self ::INVALID ;
@@ -63,16 +70,19 @@ public function handle(ExceptionNotifyManager $exceptionNotifyManager): int
63
70
throw $ runtimeException ;
64
71
} finally {
65
72
$ this ->laravel ->terminating (function () use ($ runtimeException ): void {
66
- $ this ->output ->warning (\sprintf (
67
- <<<'warning'
68
- The exception [%s] has been thrown.
69
- Please check whether the channel [%s] has received an exception report.
70
- If not, please find the reason in the default log channel.
71
- warning,
72
- $ runtimeException ::class,
73
- config ('exception-notify.default ' ),
73
+ $ this ->components ->warn (\sprintf (
74
+ 'The exception [%s] has been thrown. ' ,
75
+ $ this ->warned ($ runtimeException ::class)
76
+ ));
77
+ $ this ->components ->warn (\sprintf (
78
+ 'Please check whether the exception-notify channel [%s] has received an exception report. ' ,
79
+ $ this ->warned (config ('exception-notify.default ' ))
80
+ ));
81
+ $ this ->components ->warn (\sprintf (
82
+ 'If not, please find the reason in the default log channel [%s]. ' ,
83
+ $ this ->warned (config ('logging.default ' ))
74
84
));
75
- $ this ->output -> success ('Testing done. ' );
85
+ $ this ->components -> info ('Testing done. ' );
76
86
});
77
87
}
78
88
}
@@ -86,6 +96,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
86
96
$ this ->configureableInitialize ($ input , $ output );
87
97
88
98
$ channel = $ this ->option ('channel ' ) and config ()->set ('exception-notify.default ' , $ channel );
99
+ $ connection = $ this ->option ('queue-connection ' ) and config ()->set ('queue.default ' , $ connection );
89
100
90
101
collect (config ('exception-notify.channels ' ))->each (function (array $ configuration , string $ name ): void {
91
102
if ('notify ' === ($ configuration ['driver ' ] ?? $ name )) {
@@ -107,4 +118,9 @@ function (Client $client): Client {
107
118
}
108
119
});
109
120
}
121
+
122
+ private function warned (string $ string ): string
123
+ {
124
+ return "<fg=yellow;options=bold> $ string</> " ;
125
+ }
110
126
}
0 commit comments