Skip to content

Instantly share code, notes, and snippets.

@havvg
Created October 16, 2014 11:35
Show Gist options
  • Save havvg/794104153f0c0af51553 to your computer and use it in GitHub Desktop.
Save havvg/794104153f0c0af51553 to your computer and use it in GitHub Desktop.
Monolog ErrorHandler in Symfony2 apps
<?php
use Monolog\ErrorHandler;
use Psr\Log\LogLevel;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AppKernel extends Kernel
{
public function boot()
{
if (true === $this->booted) {
return;
}
parent::boot();
$logger = $this->getContainer()->get('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE);
if ($logger instanceof LoggerInterface) {
ErrorHandler::register($logger, [], LogLevel::ERROR, LogLevel::ALERT);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment