Is it possible to check the current LoggingLevel in Apex code and conditionally vary the execution?
E.g.
// Somehow detect the current logging level here?
System.LoggingLevel level = LoggingLevel.FINEST;
if(level == LoggingLevel.FINEST) {
// Extra logging code that may make additional SOQL calls, etc...
// that you don't want during standard execution.
System.debug(logginglevel.INFO, level);
}
Attribution to: Daniel Ballinger
Possible Suggestion/Solution #1
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.
Attribution to: jordan.baucke
Possible Suggestion/Solution #2
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
}
Attribution to: Dizzley
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1031