Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
```

Expand Down
5 changes: 5 additions & 0 deletions config/http-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/DefaultLogWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down