Skip to content
Open
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -116,6 +118,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).
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
"Schauinsland\\SplunkLogger\\ServiceProvider"
]
}
}
},
"require": {
"ext-json": "*"
}
}
5 changes: 5 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]
];
32 changes: 20 additions & 12 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}
}
18 changes: 11 additions & 7 deletions src/SplunkLoggerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Schauinsland\SplunkLogger;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\LogRecord;
Expand All @@ -10,17 +11,20 @@ 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'),
])
->withOptions([
'verify' => env('SPLUNK_VERIFY', false),
])->post(env('SPLUNK_URL'), $payload);
'Authorization' => 'Splunk ' . $splunkConfiguration['SPLUNK_TOKEN'],
])->withOptions([
'verify' => $splunkConfiguration['SPLUNK_SSL_VERIFY'],
])->post(
$splunkConfiguration['SPLUNK_URL'], $payload
);
}
}