Skip to content

Commit

Permalink
Processor fix (#9)
Browse files Browse the repository at this point in the history
* Changed processors to accept and return correct types

* Apply fixes from StyleCI

---------

Co-authored-by: Josip Milotić <[email protected]>
Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
3 people authored Sep 15, 2023
1 parent b2aa1c8 commit 634c295
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
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);
}
}

0 comments on commit 634c295

Please sign in to comment.