Debug log levels won't stay at the level I put them.

Issue #791 resolved
Maksim Demin created an issue

Illuminated Cloud Version: 1.8.1.2 Build 2071031081708 IntelliJ: Ultimate 2017.2.6

If I run some code in execute anonymous and set the log levels all to info, the levels work fine and are respected.

However, when I try to run a test, some of the log levels jump to finest and I am reaching the maximum log size.

Is this a bug? Or am I missing some setting when running the test?

Comments (5)

  1. Scott Wells repo owner

    Well, let me explain how it works and then perhaps you can let me know whether that explains the behavior you're seeing. There are three places in IC where you can set log levels/trace flags:

    1. In the Log Viewer tool window.
    2. In the Anonymous Apex tool window.
    3. For each unit test run configuration.

    When the first two tool windows are first opened, they query the current log level/trace flag from the server. In particular, they query the exact same one used by Developer Console because of this:

    https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_debugging_debug_log_precedence.htm

    Notice that Developer Console's trace flag takes top priority. Before I started to co-opt that particular trace flag and associated log level, it was virtually impossible to predict the logging results of a process started by IC.

    When you make changes to the configured log levels in Log Viewer, that trace flag is updated immediately. Similarly when you run a script from Anonymous Apex, the trace flag is updated with those configured log levels. And as you'd probably guess, when you run an Apex unit test run configuration, the trace flag is updated with those configured log levels.

    In order to ensure that the trace flag/log levels are around long enough to be used, IC first tries to reuse the existing one updating the details as required, but if necessary it creates a brand new one. The trace flag it creates is set to expire two hours from the time of creation so that it's around long enough to be useful but not so long as to clutter the org.

    So my guess is that you're seeing various configured log levels overwriting each other as you move from tool to tool, and you might also be seeing the trace flag in the org expire after two hours and logging cease.

    Let met know if your experience matches this description or not. Thanks!

  2. Maksim Demin reporter

    Thanks for the quick response! And that makes sense, I was missing how to / that I could specify a Apex unit test run configuration per unit test. I think your explanation of the log levels would be really useful to know in the offline debugger readme. Thanks again, Illuminated Cloud is awesome.

  3. Matthew Scholtz

    Hi brand new IC user here, with a similar issue. Can someone tell me how you set unit test run configuration? I don't see where to do that in IC.

  4. Scott Wells repo owner

    Matthew, there are several ways to do it:

    1. From the menu bar, Run>Edit Configurations>+>Apex Unit Tests. There's also a toolbar combo-box for run configurations.
    2. Right-click on a test class or method name and choose the appropriate context menu entry: Run, Debug, Run with Coverage, Create Configuration.
    3. You can do the same thing as above by clicking on the gutter icon beside the test class or method name.
    4. You can also do it using Alt+Enter (Windows/Linux) or Opt+Enter (Mac).

    The last is my favorite way to run tests in an ad hoc manner, and I keep an All Tests configuration for running all tests.

    Hope that helps!

  5. Log in to comment