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?
They won't be generated. However, you can specify the
LoggingLevel in your
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
+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.)