Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processor fix #9

Merged
merged 2 commits into from
Sep 15, 2023
Merged
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
16 changes: 10 additions & 6 deletions src/App/Processors/NullStringProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@

namespace Asseco\Gelf\App\Processors;

use Monolog\LogRecord;

class NullStringProcessor
{
/**
* Transform a "NULL" string record into a null value.
*
* @param array $record
* @return array
* @param LogRecord $record
* @return LogRecord
*/
public function __invoke(array $record): array
public function __invoke(LogRecord $record): LogRecord
{
foreach ($record['context'] as $key => $value) {
$context = $record->context;

foreach ($context as $key => $value) {
if (is_string($value) && strtoupper($value) === 'NULL') {
$record['context'][$key] = null;
$context[$key] = null;
}
}

return $record;
return $record->with(context: $context);
}
}
14 changes: 9 additions & 5 deletions src/App/Processors/RenameIdFieldProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@

namespace Asseco\Gelf\App\Processors;

use Monolog\LogRecord;

class RenameIdFieldProcessor
{
/**
* Rename "id" field to "_id" (additional field 'id' is not allowed).
*
* @see https://github.com/hedii/laravel-gelf-logger/issues/33
*/
public function __invoke(array $record): array
public function __invoke(LogRecord $record): LogRecord
{
foreach ($record['context'] as $key => $value) {
$context = $record->context;

foreach ($context as $key => $value) {
if ($key === 'id' && !array_key_exists('_id', $record['context'])) {
unset($record['context']['id']);
unset($context['id']);

$record['context']['_id'] = $value;
$context['_id'] = $value;
}
}

return $record;
return $record->with(context: $context);
}
}
Loading