Skip to content

Commit d56819d

Browse files
authored
feat: Allowed user-defined formatterInterface in opentelemetry-logger-monolog (#458)
* Allowed user-defined formatterInterface * Fixed Phan errors
1 parent 53615bb commit d56819d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Logs/Monolog/src/Handler.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ class Handler extends AbstractProcessingHandler
1515
/** @var API\LoggerInterface[] */
1616
private array $loggers = [];
1717
private API\LoggerProviderInterface $loggerProvider;
18+
private ?FormatterInterface $formatterInterface;
1819

1920
/**
2021
* @psalm-suppress InvalidArgument
2122
*/
22-
public function __construct(API\LoggerProviderInterface $loggerProvider, $level, bool $bubble = true)
23+
public function __construct(API\LoggerProviderInterface $loggerProvider, $level, bool $bubble = true, ?FormatterInterface $formatterInterface = null)
2324
{
2425
parent::__construct($level, $bubble);
2526
$this->loggerProvider = $loggerProvider;
27+
$this->formatterInterface = $formatterInterface;
2628
}
2729

2830
protected function getLogger(string $channel): API\LoggerInterface
@@ -36,7 +38,7 @@ protected function getLogger(string $channel): API\LoggerInterface
3638

3739
protected function getDefaultFormatter(): FormatterInterface
3840
{
39-
return new NormalizerFormatter();
41+
return $this->formatterInterface ?? new NormalizerFormatter();
4042
}
4143

4244
/**

0 commit comments

Comments
 (0)