Say if my code has 5 System.debug('some text') and my apex log level is set to 'error', will the above system.debug be generated in the system but not shown to me? Or is it that it will not be generated at all?


2 Answers 2


They won't be generated. However, you can specify the LoggingLevel in your debug statements:

system.debug(LoggingLevel.ERROR, '<content>');

This principle also applies if you want some finer details. The following won't be output even if the level for your particular log is set to DEBUG:

system.debug(LoggingLevel.FINEST, '<content>);
  • if I have used System.debug(logging level as debug), and my logging level is set to error. will the debug log above use up any memory or affect performance in any way?
    – user36984
    Aug 31, 2016 at 17:52
  • Yeah it may still have a minor impact on performance...I could profile it but might not get to that right away.
    – Adrian Larson
    Aug 31, 2016 at 17:53
  • Will it use up memory to write to logs but not show it to me?
    – user36984
    Aug 31, 2016 at 17:54
  • A trivial amount, surely.
    – Adrian Larson
    Aug 31, 2016 at 17:55
  • thanks Adrian, 1 last question, is it possible to find debug logs in any way if logging level was set to error?
    – user36984
    Aug 31, 2016 at 17:57

+1 to Adrian's answer.

Just want to add a point about the cost of logging calls. If the string passed is a constant e.g. 'some text' (or a simple string concatenation) then yes the cost is likely to be negligible as there is no work done (or next to no work done) in creating the string that is eventually thrown away if the logging is turned off.

However I have seen debugging calls of this form:

System.debug('json of SObject is ' + JSON.serializePretty(obj));
System.debug('contact SObject is ' + contact);

and in these cases the cost of creating the string is potentially significant because many fields are combined into the debugging string and it is your CPU limit that is being consumed to do that work. So add such logging with caution.

(Java logging frameworks have methods such as isDebugEnabled to avoid this cost where it is significant but Apex doesn't.)

  • Ew, yeah serialization of any form is going to be bad, but I suspect serializePretty is even worse than normal.
    – Adrian Larson
    Aug 31, 2016 at 18:04
  • Will CPU time be consumed even if there is no active trace flag?
    – bafuda
    Aug 31, 2016 at 18:37
  • 2
    @bafuda Yes. The point is that CPU time is used to build the string that is passed into the logging API and then inside the API either nothing is done or more CPU is used to write the data out to the log.
    – Keith C
    Aug 31, 2016 at 19:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .