File tree Expand file tree Collapse file tree 4 files changed +46
-5
lines changed Expand file tree Collapse file tree 4 files changed +46
-5
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,12 @@ return [
55
55
* The log channel used to write the request.
56
56
*/
57
57
'log_channel' => env('LOG_CHANNEL', 'stack'),
58
-
58
+
59
+ /*
60
+ * The log level used to log the request.
61
+ */
62
+ 'log_level' => 'info',
63
+
59
64
/*
60
65
* Filter out body fields which will never be logged.
61
66
*/
Original file line number Diff line number Diff line change 15
15
'log_writer ' => \Spatie \HttpLogger \DefaultLogWriter::class,
16
16
17
17
/*
18
- * The log channel used to write the request.
19
- */
18
+ * The log channel used to write the request.
19
+ */
20
20
'log_channel ' => env ('LOG_CHANNEL ' , 'stack ' ),
21
21
22
+ /*
23
+ * The log level used to log the request.
24
+ */
25
+ 'log_level ' => 'info ' ,
26
+
22
27
/*
23
28
* Filter out body fields which will never be logged.
24
29
*/
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ public function logRequest(Request $request)
13
13
{
14
14
$ message = $ this ->formatMessage ($ this ->getMessage ($ request ));
15
15
16
- Log::channel (config ('http-logger.log_channel ' ))->info ( $ message );
16
+ Log::channel (config ('http-logger.log_channel ' ))->log ( config ( ' http-logger.log_level ' , ' info ' ), $ message );
17
17
}
18
18
19
19
public function getMessage (Request $ request )
@@ -37,7 +37,7 @@ protected function formatMessage(array $message)
37
37
$ headersAsJson = json_encode ($ message ['headers ' ]);
38
38
$ files = $ message ['files ' ]->implode (', ' );
39
39
40
- return "{$ message ['method ' ]} {$ message ['uri ' ]} - Body: {$ bodyAsJson } - Headers: {$ headersAsJson } - Files: " . $ files ;
40
+ return "{$ message ['method ' ]} {$ message ['uri ' ]} - Body: {$ bodyAsJson } - Headers: {$ headersAsJson } - Files: " . $ files ;
41
41
}
42
42
43
43
public function flatFiles ($ file )
Original file line number Diff line number Diff line change @@ -118,4 +118,35 @@ public function it_logs_multiple_files_in_an_array()
118
118
$ this ->assertStringContainsString ('first.doc ' , $ log );
119
119
$ this ->assertStringContainsString ('second.doc ' , $ log );
120
120
}
121
+
122
+ /** @test */
123
+ public function it_logs_using_the_default_log_level ()
124
+ {
125
+ $ request = $ this ->makeRequest ('post ' , $ this ->uri , [
126
+ 'name ' => 'Name ' ,
127
+ ]);
128
+
129
+ $ this ->logger ->logRequest ($ request );
130
+
131
+ $ log = $ this ->readLogFile ();
132
+
133
+ $ this ->assertStringContainsString ('testing.INFO ' , $ log );
134
+ $ this ->assertStringContainsString ('"name":"Name ' , $ log );
135
+ }
136
+
137
+ /** @test */
138
+ public function it_logs_using_the_configured_log_level ()
139
+ {
140
+ config (['http-logger.log_level ' => 'debug ' ]);
141
+ $ request = $ this ->makeRequest ('post ' , $ this ->uri , [
142
+ 'name ' => 'Name ' ,
143
+ ]);
144
+
145
+ $ this ->logger ->logRequest ($ request );
146
+
147
+ $ log = $ this ->readLogFile ();
148
+
149
+ $ this ->assertStringContainsString ('testing.DEBUG ' , $ log );
150
+ $ this ->assertStringContainsString ('"name":"Name ' , $ log );
151
+ }
121
152
}
You can’t perform that action at this time.
0 commit comments