Detect the current LoggingLevel in Apex

Is it possible to check the current LoggingLevel in Apex code and conditionally vary the execution?


// 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);


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.

Source : Link , Question Author : Daniel Ballinger , Answer Author : Daniel Ballinger

Leave a Comment