Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ff537a005 | |||
| 0b8e72fb7b | |||
| 5c1e81d86a |
13
README.md
13
README.md
@@ -10,10 +10,18 @@ This Laravel 12 package captures every log record emitted by your application in
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Assuming the package is required locally via Composer path repository (as in this project):
|
Adding the private Git Repository to your composer.json:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer require herrleinit/loghandler:@dev
|
"require": {
|
||||||
|
"herrleinit/loghandler": "^1.0"
|
||||||
|
},
|
||||||
|
"repositories": [
|
||||||
|
{
|
||||||
|
"type": "vcs",
|
||||||
|
"url": "https://git.hacker.schule/herrleinIT/loghandler.git"
|
||||||
|
}
|
||||||
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
Laravel will auto-discover the `LogHandlerServiceProvider`.
|
Laravel will auto-discover the `LogHandlerServiceProvider`.
|
||||||
@@ -34,6 +42,7 @@ Laravel will auto-discover the `LogHandlerServiceProvider`.
|
|||||||
LOGHANDLER_TIMEOUT_MS=3000
|
LOGHANDLER_TIMEOUT_MS=3000
|
||||||
LOGHANDLER_RETRY_TIMES=0
|
LOGHANDLER_RETRY_TIMES=0
|
||||||
LOGHANDLER_INCLUDE_TRACE=false
|
LOGHANDLER_INCLUDE_TRACE=false
|
||||||
|
LOGHANDLER_EXCLUDE_LEVELS=debug,info
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **Logging stack** – ensure the `loghandler` channel participates in your default stack:
|
3. **Logging stack** – ensure the `loghandler` channel participates in your default stack:
|
||||||
|
|||||||
@@ -8,4 +8,8 @@ return [
|
|||||||
'timeout_ms' => env('LOGHANDLER_TIMEOUT_MS', 3000),
|
'timeout_ms' => env('LOGHANDLER_TIMEOUT_MS', 3000),
|
||||||
'retry_times' => env('LOGHANDLER_RETRY_TIMES', 0),
|
'retry_times' => env('LOGHANDLER_RETRY_TIMES', 0),
|
||||||
'include_trace' => env('LOGHANDLER_INCLUDE_TRACE', false),
|
'include_trace' => env('LOGHANDLER_INCLUDE_TRACE', false),
|
||||||
|
'excluded_levels' => array_values(array_filter(array_map(
|
||||||
|
static fn (string $level): string => strtolower($level),
|
||||||
|
array_map('trim', explode(',', (string) env('LOGHANDLER_EXCLUDE_LEVELS', 'debug,info')))
|
||||||
|
))),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ use ErrorException;
|
|||||||
use GuzzleHttp\ClientInterface;
|
use GuzzleHttp\ClientInterface;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Illuminate\Contracts\Config\Repository;
|
use Illuminate\Contracts\Config\Repository;
|
||||||
|
use Monolog\Level;
|
||||||
use Monolog\LogRecord;
|
use Monolog\LogRecord;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
use ValueError;
|
||||||
|
|
||||||
class LogForwarder
|
class LogForwarder
|
||||||
{
|
{
|
||||||
@@ -24,6 +26,12 @@ class LogForwarder
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$excludedLevels = $this->resolveExcludedLevels($settings);
|
||||||
|
|
||||||
|
if ($this->shouldExcludeLevel($record->level, $excludedLevels)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$endpoint = (string) ($settings['endpoint'] ?? '');
|
$endpoint = (string) ($settings['endpoint'] ?? '');
|
||||||
$token = (string) ($settings['token'] ?? '');
|
$token = (string) ($settings['token'] ?? '');
|
||||||
|
|
||||||
@@ -141,4 +149,47 @@ class LogForwarder
|
|||||||
|
|
||||||
return (string) ($record->context['trace'] ?? '');
|
return (string) ($record->context['trace'] ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $settings
|
||||||
|
* @return Level[]
|
||||||
|
*/
|
||||||
|
private function resolveExcludedLevels(array $settings): array
|
||||||
|
{
|
||||||
|
$levels = $settings['excluded_levels'] ?? [];
|
||||||
|
|
||||||
|
if (! is_array($levels)) {
|
||||||
|
$levels = [$levels];
|
||||||
|
}
|
||||||
|
|
||||||
|
$resolved = [];
|
||||||
|
|
||||||
|
foreach ($levels as $level) {
|
||||||
|
if (! is_string($level) || $level === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$resolved[] = Level::fromName($level);
|
||||||
|
} catch (ValueError) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $resolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Level[] $excludedLevels
|
||||||
|
*/
|
||||||
|
private function shouldExcludeLevel(Level $recordLevel, array $excludedLevels): bool
|
||||||
|
{
|
||||||
|
foreach ($excludedLevels as $level) {
|
||||||
|
if ($recordLevel === $level) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user