Skip to content

Commit

Permalink
added configuration to be able to disable some features
Browse files Browse the repository at this point in the history
  • Loading branch information
freezer278 committed Dec 10, 2022
1 parent 6ce11b6 commit 56366a7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,37 @@ FLUENTD_HOST=127.0.0.1
FLUENTD_PORT=24224
```

## Configuration

In config file `laravel_fluentd_logger.php` you can make some adjustments:

- Disable some features
```php
'features_enabled' => [
'request_log' => false,
'db_query_log' => false,
'queue_log' => false,
],
```
- Overwrite default fluentd log handler
```php
// optionally override \Vmorozov\LaravelFluentdLogger\Logs\FluentHandler class to customize behaviour
'handler' => SomeCustomHandler::class,
```
- Change log tag format
```php
'tagFormat' => '{{app_name}}.{{level_name}}',
```
- Overwrite some options for fluentd sdk classes
```php
/** @see https://github.com/fluent/fluent-logger-php/blob/master/src/FluentLogger.php */
'options' => [],

/** @see https://github.com/fluent/fluent-logger-php/blob/master/src/PackerInterface.php */
// specified class name
'packer' => null,
```

## Testing

```bash
Expand Down
9 changes: 9 additions & 0 deletions config/laravel_fluentd_logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@
'processors' => [],

'tagFormat' => '{{app_name}}.{{level_name}}',

/**
* Here you can disable some features if you don`t need them
*/
'features_enabled' => [
'request_log' => true,
'db_query_log' => true,
'queue_log' => true,
],
];
11 changes: 9 additions & 2 deletions src/LaravelFluentdLoggerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ private function initTracing(): void
$action = $this->app->make(MakeQueueTraceAwareAction::class);
$action->execute();

$this->initQueueJobsLog();
$this->initDbQueryLog();
$config = config('laravel_fluentd_logger');

if ($config['features_enabled']['db_query_log'] ?? true) {
$this->initDbQueryLog();
}

if ($config['features_enabled']['queue_log'] ?? true) {
$this->initQueueJobsLog();
}
}

private function initQueueJobsLog(): void
Expand Down
4 changes: 4 additions & 0 deletions src/Middleware/LogRequestMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public function terminate($request, $response)

private function logRequest($request, $response): void
{
if (!config('laravel_fluentd_logger.features_enabled.request_log', true)) {
return;
}

Log::info('Request log', $this->createLogContext($request, $response));
}

Expand Down

0 comments on commit 56366a7

Please sign in to comment.