I wanted to override the logger.filelog service from filelog module to make use of my own parser.
An error occurred through drush cim
and drush cr
when the new custom module that overrides the service is enabled.
The website encountered an unexpected error. Please try again later.
Symfony\Component\DependencyInjection\Exception\LogicException: Service 'logger.filelog' for consumer 'logger.factory' does not implement Psr\Log\LoggerInterface. in Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass->processServiceCollectorPass() (line 182 of /app/docroot/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php).
My custom modules structure looks like this
custom_module
- src
- Logger
- TestFilelog.php
CustomModuleServiceProvider.php
custom_module.info.yml
custom_module.module
Currently the service provider class has implemented ServiceModifierInterface
and altered the original logger.filelog service by setting its class to Drupal\custom_module\Logger\TestFilelog
.
class CustomModuleServiceProvider implements ServiceModifierInterface {
public function alter(ContainerBuilder $container) {
if ($container->has('logger.filelog')) {
$definition = $container->getDefinition('logger.filelog');
$definition->setClass('Drupal\custom_module\Logger\TestFilelog');
}
}
}
TestFilelog.php
namespace Drupal\custom_module\Logger;
use Drupal\filelog\Logger\FileLog;
class TestFileLog extends FileLog {
protected function render($level, $message, array $context = []): string {
$plainString = parent::render($level, $message, $context);
$custom_channel = [
'filter_custom_channel'
];
if (in_array($context['channel'], $custom_channel)) {
$plainString = $this->parseStrMasking($plainString);
}
return $plainString;
}
protected function parseStrMasking(string $pureString) {
$finalString = $pureString;
return $finalString;
}
}
I see that Drupal\filelog\Logger\FileLog;
has use RfcLoggerTrait;
which does implement the Psr\Log\LoggerInterface
, what am I missing here??