1

My java application which is using SLF4J is running on Unix box and my code has entries like :

if (LOG.isDebugEnabled())
                    LOG.debug("There is nothing in the cache for " + quote.getObject().getObjectId() + " - using the init quote");

I try to enable logging at ALL or DEBUG or TRACE via JMX but still above log statement doesn't get printed. All statement without "isDebugEnabled()" get printed.

Any ideas what can be done to enable these log statements? I cannot change logback.xml and only use JMX to change log levels.

Lokesh
  • 7,810
  • 6
  • 48
  • 78
  • [this](https://stackoverflow.com/questions/18102898/how-can-i-change-log-level-of-single-logger-in-runtime) may help – a_a Aug 22 '17 at 12:30
  • Can you attach a debugger to see how LOG is configured? Also note that logback can be configured to expose its configuration over JMX – Thorbjørn Ravn Andersen Aug 25 '17 at 08:58

1 Answers1

0

If I've understood you correctly, when you say "All statements without isDebugEnabled() get printed", you mean this gets printed:

LOG.debug("There is nothing in the cache for " + quote.getObject().getObjectId() + " - using the init quote");

but this doesn't:

if (LOG.isDebugEnabled())
    LOG.debug("There is nothing in the cache for " + quote.getObject().getObjectId() + " - using the init quote");

That doesn't make sense, since LOG.debug() would internally do the equivalent of if (isDebugEnabled()). Therefore you should run your code through a debugger to find out what is going on.

If you mean that LOG.debug(...) does NOT get printed but other levels do, you should follow the link in @a_a's comment to set the level programmatically to Debug.

DodgyCodeException
  • 5,963
  • 3
  • 21
  • 42