Symfony Error Log Event

[Solved] Symfony Error Log Event | Php - Code Explorer | yomemimo.com
Question : symfony error log event

Answered by : enzo-beauchamp

// src/AppBundle/Util/MonologDBHandler.php
namespace AppBundle\Util;
use AppBundle\Entity\Log;
use Doctrine\ORM\EntityManagerInterface;
use Monolog\Handler\AbstractProcessingHandler;
class MonologDBHandler extends AbstractProcessingHandler
{ /** * @var EntityManagerInterface */ protected $em; /** * MonologDBHandler constructor. * @param EntityManagerInterface $em */ public function __construct(EntityManagerInterface $em) { parent::__construct(); $this->em = $em; } /** * Called when writing to our database * @param array $record */ protected function write(array $record) { $logEntry = new Log(); $logEntry->setMessage($record['message']); $logEntry->setLevel($record['level']); $logEntry->setLevelName($record['level_name']); $logEntry->setExtra($record['extra']); $logEntry->setContext($record['context']); $this->em->persist($logEntry); $this->em->flush(); }
}

Source : https://nehalist.io/logging-events-to-database-in-symfony/ | Last Update : Mon, 24 Oct 22

Answers related to symfony error log event

Code Explorer Popular Question For Php