Skip to content

Commit

Permalink
Fix for serializable config (#50)
Browse files Browse the repository at this point in the history
* Fix for serializable config

* Fix for serializable config
  • Loading branch information
LauJosefsen authored Feb 19, 2024
1 parent ba570f4 commit 1db2f1b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/FilebeatLoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Cego;

use Throwable;
use TypeError;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Processor\ProcessorInterface;

class FilebeatLoggerFactory
{
Expand All @@ -28,7 +30,13 @@ public function __invoke(array $config): Logger
$logger->pushProcessor(new FilebeatContextProcessor($extras));

if (isset($config['httpContextProcessor'])) {
$logger->pushProcessor($config['httpContextProcessor']);
$processor = new $config['httpContextProcessor']();

if ( ! $processor instanceof ProcessorInterface) {
throw new TypeError('The httpContextProcessor must be an reference to a class implementing Monolog\Processor\ProcessorInterface');
}

$logger->pushProcessor($processor);
} else {
$logger->pushProcessor(new FilebeatHttpContextProcessor());
}
Expand Down

0 comments on commit 1db2f1b

Please sign in to comment.