function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HaroldCHaroldC 

Set logging at the class level

I'm trying to override the logging at the class level.  I'm trying to debug 1 class, but it's nearly impossible to find anything for that class in the log because there is so much information for all the other classes and triggers.  So I try going to the classes that I don't care about and at the class detail level I choose log filters, overide and set everything to none.  As soon as I click on another class to set its log level and come back to the first class all the filters reset.  I don't get how I can save those filters, there's no save button.  Anyone have an idea how to set and save the log filters at the class level?  I'd like to shut off all the classes except for the one I'm debugging.

 

Thanks

crop1645crop1645

The way I workaround this issue is that every System.debug statement is written as:

 

System.debug(FlowControl.getLogLevel(),'my debug stmt');

 

and I have a singleton Static class with a private variable: private static LoggingLevel  logLevel      = LoggingLevel.INFO;

 

and two methods getLogLevel() and setLogLevel(LoggingLevel newLoglevel)

 

Then, in my test code, I raise and lower the log level as desired (for example, if running my Apex Test Run at Apex Code INFO, I'll setLogLevel to LoggingLevel.DEBUG for all my record setup logic and then call setLoglevel(LoggingLevel.INFO) before my code of interest executes. 

 

This way, you can dynamically turn on/off whole swathes of your debug logs based on where you are in the test execution.