The Summer ’15 release notes have a section called Receive Debug Logs Predictably.
It currently states that the order of precedence for debug logs will be:
- Trace flags set in the Developer Console override all other logging logic.
- If you don’t have active trace flags, synchronous and asynchronous Apex tests execute with the default logging levels.
- If no relevant trace flags are active, and no tests are running, your API header sets your logging levels.
- If you enable system logs for a user, you get debug logs for that user’s next 20 requests.
- If your entry point sets a log level, that log level is used.
The order of points 2 and 3 seem a bit off to me.
If I explicitly set a DebuggingHeader on an API request I'd expect it to take precedence over the default values for synchronous and asynchronous Apex tests.
In fact, I'd expect an explicit DebuggingHeader to take precedence over a TraceFlag as well.
How can I control the logging level for test cases at the API call level without defining a TraceFlag? If I had to define the TraceFlag it will affect all logging for the given user.
IMHO, the following order would make more sense. All are based around excluding a previous match and the applicable record/header etc... being defined.
- The API DebuggingHeader header sets your logging levels for that transaction.
- TraceFlag for the user/class/trigger is used. This will apply when the Developer Console is actively logging, and for direct creation of TraceFlag records via the Tooling API
- If you enable system logs for a user, you get debug logs for that user’s next 20 requests.
- Synchronous and asynchronous Apex tests execute with the default logging levels.
- If your entry point sets a log level, that log level is used.
I'm not 100% sure on the position of this last point. Apparently it is for Visualforce requests that include a debugging parameter. Does it make sense for a TraceFlag or system level user log to take precedence?