Default Logger Settings values change the results of unit tests in sandboxes vs. production #453
Labels
Layer: Logger Engine
Items related to the core logging engine
Logging Source: Apex
Items related to using Logger within Apex
tests
Relates to Apex or LWC jest tests
Type: Bug
Something isn't working
Milestone
The behavior of
Logger.getUserSettings()
changes between sandbox and production environments, and can cause tests to pass in one and fail in the other unexpectedly if the set log levels are different.Example:
In the above example, no log level is set by the test or using org defaults, so
Logger.getUserSettings()
will default to picking upFINEST
as the log level in sandboxes and scratch orgs - all appears fine because the defaulting code has a specific exception made for sandboxes.However if Production has an org default set higher than this, the test will fail.
...the fix is straightforward. The logging level specified inside the test keeps the behavior consistent between environments. I think the problem here is that it changes behavior in a way we didn't expect. I'd almost rather have it fail the same way throughout than fall back to something for sandboxes only? Worth some debate at least.
The text was updated successfully, but these errors were encountered: