diff --git a/README.md b/README.md index be94f79..f5c2563 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,11 @@ return [ * It should implement `LogWriter`. */ 'log_writer' => \Spatie\HttpLogger\DefaultLogWriter::class, + + /* + * The log channel used to write the request. + */ + 'log_channel' => env('LOG_CHANNEL', 'stack'), /* * Filter out body fields which will never be logged. @@ -121,7 +126,7 @@ public function logRequest(Request $request): void $message = "{$method} {$uri} - {$bodyAsJson}"; - Log::info($message); + Log::channel(config('http-logger.log_channel'))->info($message); } ``` diff --git a/config/http-logger.php b/config/http-logger.php index 392b15d..9961d98 100644 --- a/config/http-logger.php +++ b/config/http-logger.php @@ -14,6 +14,11 @@ */ 'log_writer' => \Spatie\HttpLogger\DefaultLogWriter::class, + /* + * The log channel used to write the request. + */ + 'log_channel' => env('LOG_CHANNEL', 'stack'), + /* * Filter out body fields which will never be logged. */ diff --git a/src/DefaultLogWriter.php b/src/DefaultLogWriter.php index 6c40b06..28d1cae 100644 --- a/src/DefaultLogWriter.php +++ b/src/DefaultLogWriter.php @@ -13,7 +13,7 @@ public function logRequest(Request $request) { $message = $this->formatMessage($this->getMessage($request)); - Log::info($message); + Log::channel(config('http-logger.log_channel'))->info($message); } public function getMessage(Request $request) diff --git a/tests/TestCase.php b/tests/TestCase.php index 89aea03..3d4c632 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -68,13 +68,15 @@ protected function getPackageProviders($app): array protected function getEnvironmentSetUp($app) { - $app->config->set('logging.channels.single', [ + $logChannel = config('http-logger.log_channel'); + + $app->config->set('logging.channels.' . $logChannel, [ 'driver' => 'single', 'path' => $this->getLogFile(), 'level' => 'debug', ]); - $app->config->set('logging.default', 'single'); + $app->config->set('logging.default', $logChannel); } protected function setUpRoutes()