From c3ea4565f07b6598b9c9a98cd7f45505f189f16c Mon Sep 17 00:00:00 2001 From: Gent Uka Date: Wed, 5 Mar 2025 15:30:22 +0100 Subject: [PATCH 1/7] refactor: use Laravel native Env Variable and Configuration --- src/Configuration.php | 5 +++++ src/SplunkLoggerHandler.php | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Configuration.php b/src/Configuration.php index 3659858..431d4da 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -4,5 +4,10 @@ 'splunk' => [ 'driver' => 'custom', 'via' => \Schauinsland\SplunkLogger\SplunkLogger::class, + 'SPLUNK_URL' => env('SPLUNK_URL'), + 'SPLUNK_TOKEN' => env('SPLUNK_TOKEN'), + 'SPLUNK_INDEX' => env('SPLUNK_INDEX'), + 'SPLUNK_SOURCE' => env('SPLUNK_SOURCE', 'schauinsland/laravel-splunk-logger'), + 'SPLUNK_SSL_VERIFY' => env('SPLUNK_SSL_VERIFY', true), ] ]; diff --git a/src/SplunkLoggerHandler.php b/src/SplunkLoggerHandler.php index 059c8bd..3b127c8 100644 --- a/src/SplunkLoggerHandler.php +++ b/src/SplunkLoggerHandler.php @@ -2,6 +2,7 @@ namespace Schauinsland\SplunkLogger; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Http; use Monolog\Handler\AbstractProcessingHandler; use Monolog\LogRecord; @@ -10,17 +11,19 @@ class SplunkLoggerHandler extends AbstractProcessingHandler { public function write(LogRecord $record): void { + $splunkConfiguration = Config::get('logging.channels.splunk'); + $payload = [ 'event' => json_encode($record->toArray()), - 'source' => env('SPLUNK_SOURCE'), - 'index' => env('SPLUNK_INDEX'), + 'source' => $splunkConfiguration['SPLUNK_SOURCE'], + 'index' => $splunkConfiguration['SPLUNK_INDEX'], ]; Http::withHeaders([ - 'Authorization' => 'Splunk ' . env('SPLUNK_TOKEN'), + 'Authorization' => 'Splunk ' . $splunkConfiguration['SPLUNK_TOKEN'], ]) ->withOptions([ - 'verify' => env('SPLUNK_VERIFY', false), - ])->post(env('SPLUNK_URL'), $payload); + 'verify' => $splunkConfiguration['SPLUNK_VERIFY'], + ])->post($splunkConfiguration['SPLUNK_URL'], $payload); } } From 6c643328999259613665cc30029a2aba59a55c1b Mon Sep 17 00:00:00 2001 From: Gent Uka Date: Wed, 5 Mar 2025 16:05:14 +0100 Subject: [PATCH 2/7] docs: improve LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 45c311c..41efa40 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2025 Gent Uka +Copyright (c) 2025 schauinsland-reisen gmbh Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 465c5a6c08677589a4ab500663bd33148ce6b73f Mon Sep 17 00:00:00 2001 From: Gent Uka Date: Wed, 5 Mar 2025 17:07:09 +0100 Subject: [PATCH 3/7] build: add json ext --- composer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 99e0e02..1c6c02d 100644 --- a/composer.json +++ b/composer.json @@ -21,5 +21,8 @@ "Schauinsland\\SplunkLogger\\ServiceProvider" ] } - } + }, + "require": { + "ext-json": "*" + } } From 202b19c972816786ae52bc4a6b1be4f975878a69 Mon Sep 17 00:00:00 2001 From: Gent Uka Date: Wed, 5 Mar 2025 17:07:46 +0100 Subject: [PATCH 4/7] refactor: code style and use splunk_ssl_verify --- src/SplunkLoggerHandler.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/SplunkLoggerHandler.php b/src/SplunkLoggerHandler.php index 3b127c8..7819e07 100644 --- a/src/SplunkLoggerHandler.php +++ b/src/SplunkLoggerHandler.php @@ -21,9 +21,10 @@ public function write(LogRecord $record): void Http::withHeaders([ 'Authorization' => 'Splunk ' . $splunkConfiguration['SPLUNK_TOKEN'], - ]) - ->withOptions([ - 'verify' => $splunkConfiguration['SPLUNK_VERIFY'], - ])->post($splunkConfiguration['SPLUNK_URL'], $payload); + ])->withOptions([ + 'verify' => $splunkConfiguration['SPLUNK_SSL_VERIFY'], + ])->post( + $splunkConfiguration['SPLUNK_URL'], $payload + ); } } From c2653df8dcd413cb22aa4977b7ab29d3a4c8ba1e Mon Sep 17 00:00:00 2001 From: Gent Uka Date: Wed, 5 Mar 2025 17:52:27 +0100 Subject: [PATCH 5/7] feat: add support for publishing configuration --- src/ServiceProvider.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 41b8b7e..c898e0b 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -6,18 +6,26 @@ class ServiceProvider extends BaseServiceProvider { - private string $configPath = '/Configuration.php'; + private string $configPath = '/Configuration.php'; - public function boot(): void - { - $this->loadSplunkConfig(); - } + public function boot(): void + { + $this->publishes( + [__DIR__ . $this->configPath => config_path('laravel-splunk-logger.php')], + ); - private function loadSplunkConfig(): void - { - $this->mergeConfigFrom( - __DIR__ . $this->configPath, - 'logging.channels' - ); - } + $this->mergeSplunkConfig(); + } + + private function mergeSplunkConfig(): void + { + if (config('laravel-splunk-logger')) { + return; + } + + $this->mergeConfigFrom( + __DIR__ . $this->configPath, + 'logging.channels' + ); + } } From 20f1c683850c6401f683ff7eb9c6cdb2efd9809d Mon Sep 17 00:00:00 2001 From: Gent Uka Date: Wed, 5 Mar 2025 17:52:55 +0100 Subject: [PATCH 6/7] docs: clarify configuration publishing support --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 10b500e..ab6a156 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,24 @@ For more custom logging options, refer to the [Laravel Logging Documentation](ht } ``` +## Publish Configuration (Optional) + +By default, the configuration is automatically merged into logging.php. However, you can still publish the configuration file to the config directory if needed. To publish the configuration, run: +```bash +php artisan vendor:publish --provider=Schauinsland\\SplunkLogger\\ServiceProvider +``` + +After publishing, update your `logging.php` configuration file to include the published settings: +```php +return [ + 'channels' => [ + 'splunk' => (require config_path('laravel-splunk-logger.php'))['splunk'], + ], + // Other channels... +]; +``` + + ## Bug report or Feature request If you encounter a bug or have a feature request, please [create an issue](https://github.com/schauinsland/laravel-splunk-logger/issues). From 42cd59bd2f461a14fe9dfb301083bdf8128552ca Mon Sep 17 00:00:00 2001 From: Gent Uka Date: Thu, 6 Mar 2025 10:48:57 +0100 Subject: [PATCH 7/7] docs: improve readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ab6a156..cdf28b5 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ * [Example .env](#example-env) * [Usage](#usage) * [Output Example](#output-example) + * [Publish Configuration (Optional)](#publish-configuration-optional) * [Bug report or Feature request](#bug-report-or-feature-request) * [Want to Contribute?](#want-to-contribute) * [Code of Conduct](#code-of-conduct) @@ -33,6 +34,7 @@ The library automatically merges with Laravel's `config/logging.php`, eliminatin - **Captures All Laravel Errors in Debug Mode**: Automatically logs all Laravel exceptions and errors to Splunk when the application is in debug mode, providing comprehensive error insights during development. +Additionally, it is possible and optional to merge the configuration manually if needed. For more details, see [Publish Configuration (Optional)](#publish-configuration-optional). ## Installation