diff --git a/src/Processor/CallableContextProcessor.php b/src/Processor/CallableContextProcessor.php index 265b7fd..d9a9254 100644 --- a/src/Processor/CallableContextProcessor.php +++ b/src/Processor/CallableContextProcessor.php @@ -27,7 +27,7 @@ public function __invoke(LogRecord $record): LogRecord } foreach ($context as $key => &$value) { - if (\is_callable($value)) { + if (!is_string($value) && \is_callable($value)) { try { $value = $value(); } diff --git a/tests/Processor/CallableContextTest.php b/tests/Processor/CallableContextTest.php index 04ffba1..d4593ff 100644 --- a/tests/Processor/CallableContextTest.php +++ b/tests/Processor/CallableContextTest.php @@ -60,4 +60,29 @@ public function testCallbackValueIsRemoved(): void $this->assertTrue($callbackExecuted); } + + public function testStringFunctionIsNotCalled():void + { + $stringFunction = 'Stefna\Logger\Processor\testingFunction'; + + $mainLogger = $this->createMock(LoggerInterface::class); + $logger = new ProcessLogger($mainLogger, new CallableContextProcessor()); + $msg = 'testCallbackValueIsRemoved'; + $callbackExecuted = false; + + $this->expectOutputString(""); + $logger->debug($msg, [ + "section" => $stringFunction, + CallableContextProcessor::CALLBACK => function () use (&$callbackExecuted) { + $callbackExecuted = true; + }, + ]); + + $this->assertTrue($callbackExecuted); + } +} + +function testingFunction() +{ + print("should not print this"); }