Skip to content

Commit

Permalink
Merge pull request #29 from ucan-lab/refactor-listner-replace
Browse files Browse the repository at this point in the history
refactor: Allow listeners to be replaced
  • Loading branch information
ucan-lab authored Apr 7, 2024
2 parents 3e73e26 + 3d0506d commit 6ba656c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LOG_HTTP_CLIENT_REQUEST_ENABLED=true
LOG_HTTP_CLIENT_RESPONSE_ENABLED=true
```

### Option config file publish
### [Option] Publish the config file

Copy the package config to your local config with the publish command:

Expand Down
13 changes: 13 additions & 0 deletions config/blink-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
| Blink Logger
|--------------------------------------------------------------------------
*/

return [
/*
|--------------------------------------------------------------------------
Expand All @@ -18,6 +19,12 @@
'enabled' => env('LOG_QUERY_ENABLED', false),
'channel' => config('logging.default'),
'slow_query_time' => env('LOG_SQL_SLOW_QUERY_TIME', 2000), // ms
'listeners' => [
\Illuminate\Database\Events\QueryExecuted::class => \LaravelBlinkLogger\Listeners\QueryExecutedLogger::class,
\Illuminate\Database\Events\TransactionBeginning::class => \LaravelBlinkLogger\Listeners\TransactionBeginningLogger::class,
\Illuminate\Database\Events\TransactionCommitted::class => \LaravelBlinkLogger\Listeners\TransactionCommittedLogger::class,
\Illuminate\Database\Events\TransactionRolledBack::class => \LaravelBlinkLogger\Listeners\TransactionRolledBackLogger::class,
],
],

'http' => [
Expand Down Expand Up @@ -64,6 +71,9 @@
'request' => [
'enabled' => env('LOG_HTTP_CLIENT_REQUEST_ENABLED', false),
'channel' => config('logging.default'),
'listeners' => [
\Illuminate\Http\Client\Events\RequestSending::class => \LaravelBlinkLogger\Listeners\RequestSendingLogger::class,
],
],

/*
Expand All @@ -74,6 +84,9 @@
'response' => [
'enabled' => env('LOG_HTTP_CLIENT_RESPONSE_ENABLED', false),
'channel' => config('logging.default'),
'listeners' => [
\Illuminate\Http\Client\Events\RequestSending::class => \LaravelBlinkLogger\Listeners\RequestSendingLogger::class,
],
],
],
];
27 changes: 9 additions & 18 deletions src/Providers/LaravelBlinkLoggerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,8 @@

use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Database\Events\TransactionBeginning;
use Illuminate\Database\Events\TransactionCommitted;
use Illuminate\Database\Events\TransactionRolledBack;
use Illuminate\Http\Client\Events\RequestSending;
use Illuminate\Http\Client\Events\ResponseReceived;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
use LaravelBlinkLogger\Listeners\QueryExecutedLogger;
use LaravelBlinkLogger\Listeners\RequestSendingLogger;
use LaravelBlinkLogger\Listeners\ResponseReceivedLogger;
use LaravelBlinkLogger\Listeners\TransactionBeginningLogger;
use LaravelBlinkLogger\Listeners\TransactionCommittedLogger;
use LaravelBlinkLogger\Listeners\TransactionRolledBackLogger;

class LaravelBlinkLoggerServiceProvider extends ServiceProvider
{
Expand All @@ -31,10 +19,9 @@ public function boot(Repository $config, Dispatcher $events, Router $router): vo

// Query Logger
if ($config->get('blink-logger.query.enabled')) {
$events->listen(QueryExecuted::class, QueryExecutedLogger::class);
$events->listen(TransactionBeginning::class, TransactionBeginningLogger::class);
$events->listen(TransactionCommitted::class, TransactionCommittedLogger::class);
$events->listen(TransactionRolledBack::class, TransactionRolledBackLogger::class);
foreach ($config->get('blink-logger.query.listeners') as $event => $listener) {
$events->listen($event, $listener);
}
}

// HTTP Request Logger
Expand All @@ -57,12 +44,16 @@ public function boot(Repository $config, Dispatcher $events, Router $router): vo

// HTTP Client Request Logger
if ($config->get('blink-logger.http_client.request.enabled')) {
$events->listen(RequestSending::class, RequestSendingLogger::class);
foreach ($config->get('blink-logger.http_client.request.listeners') as $event => $listener) {
$events->listen($event, $listener);
}
}

// HTTP Client Response Logger
if ($config->get('blink-logger.http_client.response.enabled')) {
$events->listen(ResponseReceived::class, ResponseReceivedLogger::class);
foreach ($config->get('blink-logger.http_client.response.listeners') as $event => $listener) {
$events->listen($event, $listener);
}
}
}

Expand Down

0 comments on commit 6ba656c

Please sign in to comment.