Detect the current LoggingLevel in Apex

Unfortunately, I don't think there is a way to check the current logging level in APEX.


UPDATE: I've (Daniel) finally got around to creating an idea on the Idea Exchange to allow Apex to detect the logging level for the transaction and alter the logging accordingly - Allow apex to detect the logging level so expensive logging can be skipped.


You can vary the Logging Level by using a LoggingLevel variable in your debug calls rather than the constants. Then at least you can turn some messages on or off depending on the code you are debugging.

e.g.

// Normally, suppress messages
LoggingLevel myLogLevel = LoggingLevel.NONE;
System.debug(myLogLevel,'A debug message that does not interest me today');
...
LoggingLevel myLogLevel = LoggingLevel.DEBUG;
System.debug(myLogLevel,'A debug message that I want to see today');
...
...
if(myLogLevel == LoggingLevel.DEBUG) {
  // do conditional actions here
}

Tags:

Apex