-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MetricsPower] Added logstash processor
- Loading branch information
1 parent
0d269d2
commit 088204b
Showing
10 changed files
with
128 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* | ||
* Copyright (c) 2024 Mykhailo Shtanko fractalzombie@gmail.com | ||
* | ||
* For the full copyright and license information, please view the LICENSE.MD | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FRZB\Component\MetricsPower\Logger\Processor; | ||
|
||
use FRZB\Component\DependencyInjection\Attribute\AsTagged; | ||
use Monolog\LogRecord; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
|
||
#[AsTagged('monolog.processor')] | ||
class LogstashProcessor | ||
{ | ||
public function __construct( | ||
#[Autowire(env: 'MONOLOG_SOURCE')] | ||
private readonly string $source, | ||
) {} | ||
|
||
public function __invoke(LogRecord $record): LogRecord | ||
{ | ||
return new LogRecord( | ||
$record->datetime, | ||
$record->channel, | ||
$record->level, | ||
json_validate($record->message) ? $this->formatJson($record->message) : $record->message, | ||
$this->mapContext($record), | ||
$this->mapExtra($record), | ||
json_validate($record->formatted) ? $this->formatJson($record->formatted) : $record->formatted, | ||
); | ||
} | ||
|
||
private function formatJson(string $json): string | ||
{ | ||
$decodedJson = json_decode($json, true); | ||
|
||
return json_encode($decodedJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); | ||
} | ||
|
||
private function mapExtra(LogRecord $record): array | ||
{ | ||
return [ | ||
...$record->extra, | ||
'source' => $this->source, | ||
]; | ||
} | ||
|
||
private function mapContext(LogRecord $record): array | ||
{ | ||
return [ | ||
...$record->context, | ||
]; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
OptionsResolver/Exception/OptionsResolverLocatorException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* | ||
* Copyright (c) 2024 Mykhailo Shtanko fractalzombie@gmail.com | ||
* | ||
* For the full copyright and license information, please view the LICENSE.MD | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FRZB\Component\MetricsPower\OptionsResolver\Exception; | ||
|
||
use FRZB\Component\MetricsPower\Exception\MetricsPowerException; | ||
|
||
final class OptionsResolverLocatorException extends MetricsPowerException {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters