Skip to content

Commit

Permalink
feat(monolog): added compatibility with monolog3 and drop php7.4 / sf4 (
Browse files Browse the repository at this point in the history
#12)

* feat(monolog): added compatibility with monolog3 and drop php7.4 / sf4 and older monolog

* feat(composer): locking version to monolog 3 & php8.1

Co-authored-by: Louis Pinsembert <[email protected]>
  • Loading branch information
lpinsembert and Louis Pinsembert authored Sep 27, 2022
1 parent 543b9ba commit 887caf1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
version: ['7.4', '8.0', '8.1']
version: ['8.1']
flags: ['', '--prefer-lowest']
fail-fast: false
steps:
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
}
],
"require": {
"php": ">=7.4",
"symfony/framework-bundle": "~4.4 || ~5.0 || ~6.0",
"php": ">=8.1",
"symfony/framework-bundle": "~5.0 || ~6.0",
"symfony/monolog-bundle": "~3.0",
"symfony/expression-language": "~4.4 || ~5.0 || ~6.0",
"monolog/monolog": "^1.22 || ^2.0"
"symfony/expression-language": "~5.0 || ~6.0",
"monolog/monolog": "^3.0"
},
"require-dev": {
"atoum/atoum": "~3.4 || ~4.0",
"symfony/yaml": "~4.4 || ~5.0 || ~6.0"
"symfony/yaml": "~5.0 || ~6.0"
},
"autoload": {
"psr-0": { "": "src/" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace M6Web\Bundle\MonologExtraBundle\Processor;

use Monolog\LogRecord;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

Expand All @@ -22,16 +23,11 @@ public function __construct(ContainerInterface $container, ExpressionLanguage $e
*/
protected $configuration;

/**
* @param array $record
*
* @return array
*/
public function __invoke(array $record)
public function __invoke(LogRecord $record): LogRecord
{
$record['context'] = array_merge($this->evaluateConfiguration(), $record['context']);

return $record;
return $record->with(
context: array_merge($this->evaluateConfiguration(), $record['context'])
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

use atoum;
use M6Web\Bundle\MonologExtraBundle\Processor\ContextInformationProcessor as Base;
use Monolog\Level;
use Monolog\LogRecord;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

class ContextInformationProcessor extends atoum
{
public function testInvoke()
public function testInvoke(): void
{
$data = [ 'foo' => uniqid(), 'bar' => uniqid(), 'expr' => 'expr(container.getParameter("test"))' ];

Expand All @@ -18,8 +20,16 @@ public function testInvoke()
$processor = new Base($container, new ExpressionLanguage());
$processor->setConfiguration($data);

$record = call_user_func($processor, new LogRecord(
datetime: new \DateTimeImmutable(),
channel: uniqid('channel_', true),
level: Level::Info,
message: uniqid('message_', true),
context: []
));

$this
->array($record = call_user_func($processor, ['context' => []]))
->object($record)
->string($record['context']['foo'])
->isEqualTo($data['foo'])
->string($record['context']['bar'])
Expand Down

0 comments on commit 887caf1

Please sign in to comment.