Symfony2: how to log request duration for / dev.log logs

In dev env, Symfony2 logs SQL queries to dev.log by default. For the purposes of profiling and debugging, I would like to register a query with a runtime . This should be possible, since the "real page" profiler shows the runtime next to each request. I think the correct class is DBalLogger + a stopwatch instance, but I don’t know how and where I configure these services correctly (monolog? Samples say we should use setSQLLogger, but where can I do this in my config_dev.yml?)

+4
source share
1 answer

you can enter the monologue service and then manually add the time reference

$logger = $this->get('logger');
$timestart = microtime(true);
// Your query goes here
$timeend = microtime(true);
$logger->info("Query time: " . (($timeend - $timestart) * 1000) . "s");
+1
source

All Articles