Register Symfony

In Java, I use log4J, which is the basis of logging. In Log4j, you can do something like this:

if (log.isDebug()) {
  // do some expensive operation that should only be displayed if DEBUG is turned on
}

After reading some Symfony examples, I cannot find a way to determine if DEBUG logging is activated in the context of the current class. Is there any way to do this?

if (--need something here--) {
  $this->logMessage('Expensive operation return value: '.expensiveFunction(), 'debug');
}
+3
source share
5 answers

sort of

$this->getLogger()->getLogLevel() == sfLogger::DEBUG

.

+5
source

You should check the use of Monolog

+3
source

: sfConfig::get('sf_logging_enabled'). , . .yml.

0

you can use the symfony registration service if you are in the controller, you can call this service using this code:

if ($this->get('kernel')->isDebug()) {
 $this->get('logger')->err('my custom message');
}

If you want to improve your system, you can check out MonologBundle http://symfony.com/doc/current/logging.html

0
source

Source: https://habr.com/ru/post/1704724/


All Articles