Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow explorer logger to accept channel name #223

Merged
merged 3 commits into from
Nov 27, 2023
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
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [3.10.0]

### Added
- The configurable logger may now be a channel name.

## [3.9.0]

### Changed
Expand Down
6 changes: 6 additions & 0 deletions docs/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ To enable the logger set `EXPLORER_ELASTIC_LOGGER_ENABLED=true` in your environm
See also the [SDK](https://github.com/elastic/elasticsearch-php/blob/main/docs/logger.asciidoc) docs.
More information on loggers in Laravel can be found in [Laravel's docs](https://laravel.com/docs/logging).

If you pass a string value as the logger it will be interpreted as the name of a log channel (see Laravel's docs for more information).

Examples:
```php
'logger' => new \Psr\Log\NullLogger(),
Expand All @@ -15,3 +17,7 @@ Examples:
```php
'logger' => \Illuminate\Support\Facades\Log::channel('daily'),
```

```php
'logger' => 'daily',
```
9 changes: 8 additions & 1 deletion src/Infrastructure/Elastic/ElasticClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Elasticsearch\ClientBuilder;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Support\Facades\Log;

final class ElasticClientBuilder
{
Expand Down Expand Up @@ -65,7 +66,13 @@ public static function fromConfig(Repository $config): ClientBuilder
}

if($config->get('explorer.logging', false) && $config->has('explorer.logger')) {
$builder->setLogger($config->get('explorer.logger'));
$logger = $config->get('explorer.logger');

if(is_string($logger)) {
$logger = Log::channel($logger);
}

$builder->setLogger($logger);
}

return $builder;
Expand Down
Loading