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); }
Answer
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
Source : Link , Question Author : Daniel Ballinger , Answer Author : Daniel Ballinger