Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix for OXID 6.2 circular reference service problems
# thx to alfred (https://github.com/alfredbez) for sharing
# add to modules/functions.php
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
function getLogger() {
$loggerServiceName = LoggerInterface::class;
try {
$container = ContainerFactory::getInstance()->getContainer();
return $container->get($loggerServiceName);
} catch (ServiceCircularReferenceException $exception) {
if (strpos($exception->getMessage(), $loggerServiceName) !== false) {
$logger = new Logger('OXID Logger');
$logger->pushHandler(new StreamHandler(OX_LOG_FILE, Logger::ERROR));
$logger->critical('Not able to load logger from container');
return $logger;
}
throw $exception;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.