Skip to main content

Debugging

Symfony Debug to Error Handler Component

·260 words·2 mins
Since symfony 4.4 the symfony/debug component is deprecated. The “\Symfony\Component\Debug\ErrorHandler” class is deprecated since Symfony 4.4, use “\Symfony\Component\ErrorHandler\ErrorHandler” Running unit tests on Mascot, I noticed lots of warnings. But it was not easy as changing Symfony\Component\Debug\ExceptionHandler to Symfony\Component\ErrorHandler\ErrorHandler. Assume we have something as below 37 38 39 40 41 42 43 44 <?php $handler = new \Symfony\Component\Debug\ExceptionHandler($debug); $exception = $event->getThrowable(); if (!$exception instanceof FlattenException) { $exception = FlattenException::create($exception); } $response = Response::create($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders())->setCharset(ini_get('default_charset')); $event->setResponse($response); The Symfony\Component\ErrorHandler\ErrorHandler has no getHtml method. From the symfony docs, if you are in development mode we can use below code.

CakePHP ORM and Logging Queries

·196 words·1 min
Working with cakephp/orm library, I needed to log all the queries. Cakephp provides a way to do it via cakephp/log. 1 2 3 4 5 6 7 8 9 <?php use Cake\Log\Log; Log::config('queries', [ 'className' => 'File', 'path' => '/my/log/path/', 'file' => 'app', 'scopes' => ['queriesLog'] ]); But you are not limited, if you need to configure it to a PSR-3 logger like monolog/monolog 1 2 3 4 5 6 7 8 9 10 <?php use Cake\Log\Log; use Monolog\Logger; use Monolog\Handler\StreamHandler; Log::config('default', function () { $log = new Logger('cli'); $log->pushHandler(new StreamHandler('php://stdout')); return $log; }); That was pretty simple and it logs to cli.