2
2
3
3
namespace Naoray \LaravelGithubMonolog \Formatters ;
4
4
5
+ use Illuminate \Support \Arr ;
5
6
use Illuminate \Support \Collection ;
6
7
use Illuminate \Support \Str ;
7
8
use Illuminate \Support \Stringable ;
@@ -54,7 +55,7 @@ public function formatBatch(array $records): array
54
55
private function generateSignature (LogRecord $ record , ?Throwable $ exception ): string
55
56
{
56
57
if (! $ exception ) {
57
- return md5 ($ record ->message . json_encode ($ record ->context ));
58
+ return md5 ($ record ->message . json_encode ($ record ->context ));
58
59
}
59
60
60
61
$ trace = $ exception ->getTrace ();
@@ -64,7 +65,7 @@ private function generateSignature(LogRecord $record, ?Throwable $exception): st
64
65
$ exception ::class,
65
66
$ exception ->getFile (),
66
67
$ exception ->getLine (),
67
- $ firstFrame ? ($ firstFrame ['file ' ] ?? '' ). ': ' . ($ firstFrame ['line ' ] ?? '' ) : '' ,
68
+ $ firstFrame ? ($ firstFrame ['file ' ] ?? '' ) . ': ' . ($ firstFrame ['line ' ] ?? '' ) : '' ,
68
69
]));
69
70
}
70
71
@@ -110,7 +111,7 @@ private function formatTitle(LogRecord $record, ?Throwable $exception = null): s
110
111
private function formatContent (LogRecord $ record , ?Throwable $ exception ): string
111
112
{
112
113
return Str::of ('' )
113
- ->when ($ record ->message , fn ($ str , $ message ) => $ str ->append ("**Message:** \n{$ message }\n\n" ))
114
+ ->when ($ record ->message , fn ($ str , $ message ) => $ str ->append ("**Message:** \n{$ message }\n\n" ))
114
115
->when (
115
116
$ exception ,
116
117
function (Stringable $ str , Throwable $ exception ) {
@@ -120,8 +121,8 @@ function (Stringable $str, Throwable $exception) {
120
121
);
121
122
}
122
123
)
123
- ->when (! $ exception && ! empty ($ record ->context ), fn ($ str , $ context ) => $ str ->append ("**Context:** \n```json \n" . json_encode ($ record ->context , JSON_PRETTY_PRINT ). "\n``` \n\n" ))
124
- ->when (! empty ($ record ->extra ), fn ($ str , $ extra ) => $ str ->append ("**Extra Data:** \n```json \n" . json_encode ($ record ->extra , JSON_PRETTY_PRINT ). "\n``` \n" ))
124
+ ->when (! empty ($ record ->context ), fn ($ str , $ context ) => $ str ->append ("**Context:** \n```json \n" . json_encode (Arr:: except ( $ record ->context , [ ' exception ' ]), JSON_PRETTY_PRINT ) . "\n``` \n\n" ))
125
+ ->when (! empty ($ record ->extra ), fn ($ str , $ extra ) => $ str ->append ("**Extra Data:** \n```json \n" . json_encode ($ record ->extra , JSON_PRETTY_PRINT ) . "\n``` \n" ))
125
126
->toString ();
126
127
}
127
128
@@ -141,7 +142,7 @@ private function formatBody(LogRecord $record, string $signature, ?Throwable $ex
141
142
private function cleanStackTrace (string $ stackTrace ): string
142
143
{
143
144
return collect (explode ("\n" , $ stackTrace ))
144
- ->filter (fn ($ line ) => ! empty (trim ($ line )))
145
+ ->filter (fn ($ line ) => ! empty (trim ($ line )))
145
146
->map (function ($ line ) {
146
147
if (trim ($ line ) === '"} ' ) {
147
148
return '' ;
@@ -217,8 +218,8 @@ private function formatExceptionDetails(Throwable $exception): array
217
218
218
219
return [
219
220
'message ' => $ exception ->getMessage (),
220
- 'stack_trace ' => $ header. "\n[stacktrace] \n" . $ this ->cleanStackTrace ($ exception ->getTraceAsString ()),
221
- 'full_stack_trace ' => $ header. "\n[stacktrace] \n" . $ exception ->getTraceAsString (),
221
+ 'stack_trace ' => $ header . "\n[stacktrace] \n" . $ this ->cleanStackTrace ($ exception ->getTraceAsString ()),
222
+ 'full_stack_trace ' => $ header . "\n[stacktrace] \n" . $ exception ->getTraceAsString (),
222
223
];
223
224
}
224
225
0 commit comments