Reputation: 2154
In Java, I use log4J that is a logging framework. 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
}
Reading some Symfony examples, I am unable to find a way to determine if DEBUG logging is activated in the current class context. Is there a way to do this?
if (--need something here--) {
$this->logMessage('Expensive operation return value: '.expensiveFunction(), 'debug');
}
Upvotes: 3
Views: 3829
Reputation: 2497
you can use the symfony logger service if your are in a 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 yo can check MonologBundle http://symfony.com/doc/current/logging.html
Upvotes: 0
Reputation: 13
You can check is in debug mode with that:
if ($this->get('kernel')->isDebug()) {
...
}
This is information about logger service https://symfony.com/doc/2.8/components/console/logger.html and http://symfony.com/doc/current/cookbook/logging/index.html
Upvotes: 0
Reputation: 2314
You could also try: sfConfig::get('sf_logging_enabled').
It shows if logging is enabled.
The levels can be configured in the factories.yml.
Upvotes: 0
Reputation: 60167
something like
$this->getLogger()->getLogLevel() == sfLogger::DEBUG
should do.
Upvotes: 5