Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Logger Settings values change the results of unit tests in sandboxes vs. production #453

Closed
arbokrad opened this issue Feb 21, 2023 · 0 comments · Fixed by #452
Closed
Assignees
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

Comments

@arbokrad
Copy link

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:

@IsTest
static void noLogLevelSetByTestOrOrg_PassesSandboxButNotProd() {

	Logger.info('Hello World');
	
	// query for it - works in sandbox but not prod
	List<LogEntry__c> entries = ...;
	Assert.areEqual(1, entries.size());
}

In the above example, no log level is set by the test or using org defaults, so Logger.getUserSettings() will default to picking up FINEST 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.

@IsTest
static void logLevelSetByTest_PassesBoth() {
	Logger.getUserSettings().LoggingLevel__c = System.LoggingLevel.INFO.name();

	Logger.info('Hello World');
	
	// query for it - works in all envs
	List<LogEntry__c> entries = ...;
	Assert.areEqual(1, entries.size());
}

...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.

@jongpie jongpie added Type: Bug Something isn't working Logging Source: Apex Items related to using Logger within Apex Layer: Logger Engine Items related to the core logging engine tests Relates to Apex or LWC jest tests labels Feb 21, 2023
@jongpie jongpie self-assigned this Feb 21, 2023
jongpie added a commit that referenced this issue Mar 7, 2023
…ult field values, and making LoggerSettingsController responsible for handling prod-specific settings

Some default field values on LogEntry__c have also been updated to provide the most detailed settings OOTB

This also led to the creation of the new public method Logger.createSettings()
jongpie added a commit that referenced this issue Mar 15, 2023
… configurable fields in Slack plugin (#452)

* Added overload method LogEntryEventBuilder.setRecord(Map<Id, SObject>) to support logging maps of SObjects. Other types of maps, as well as Set<SObject>, are currently considered out of scope

* Updated System.debug() calls in Logger.cls to start with 'Nebula Logger' instead of just 'Logger' for clarity

* Updated formula field LogEntry__c.LoggingLevelWithImage__c to use a different emoji for INFO vs lower levels (DEBUG, FINE, FINER, and FINEST)

* Added inline help text about thresholds to all of the limits formula fields on LogEntry__c

* Added new AnimationRule metadata to enable confetti on the Log__c path component

* Fixed #447 by updating LogEntryEventHandler to have an extra null check when processing LogEntryTagRule__mdt rules

* Fixed #453 by simplifying Logger.getUserSettings() to always use default field values, and making LoggerSettingsController responsible for handling prod-specific settings. Some default field values on LogEntry__c have also been updated to provide the most detailed settings OOTB. This also led to the creation of the new public method Logger.createSettings().

* Updated SlackLoggerPlugin.cls to leverage a new field set, Log__c.SlackNotificationFields, to support customization of the fields shown in Slack notifications. This field set can either be directly modified (although changes may be reverted during upgrades), or by creating & specifying another field set in the custom metadata record LoggerParameter.SlackLogNotificationFieldSet

* Renamed the remote site setting Slack.remoteSite-meta.xml to LoggerSlack.remoteSite-meta.xml to consistently have some variation of the word "Log" in all metadata

* Fixed some dependabot alerts in package-lock.json

* Commented-out all asserts in the Experience Cloud site's test classes. These are copies of the classes that Salesforce typically auto-creates when Experience Cloud is first enabled in an org - they've started failing in the pipeline, and they have 0 relevance to Nebula Logger's functionality, so commenting-out the asserts is good enough for now

* Switched to installing sfdx bummer plugin in the pipeline, instead of using linked version. There seems to be an ongoing issue with newer versions of sfdx that causes issues with linking plugins - @W-12652231

* Added new extra test class NebulaLogger_E2E_Tests to test full end-to-end (E2) tests to verify certain features & behaviors, as well as to provide examples to Apex developers of how to test their usage of Nebula Logger. This just has some basic tests for now - it'll evolve over the next few releases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
2 participants