Skip to content

LoggerSettings__c cannot see the org config in tests, settings like SystemLogMessageFormat__c revert to defaults #210

@arbokrad

Description

@arbokrad

Since LoggerSettings__c is a custom setting, it is not automatically available with any pre-configured org defaults without using the @IsTest(SeeAllData=true) annotation.

@IsTest
static void Nebula_Harness() {
	// outputs using the in-code default format (creates its own LoggerSettings__c)
	Logger.debug( 'Pre-LoggerSettings Update' );

	LoggerSettings__c settings = Logger.getUserSettings();
	settings.SystemLogMessageFormat__c = '{OriginLocation__c} -- {Message__c}';

	// outputs using the updated format (above)
	Logger.debug( 'Post-LoggerSettings Update' );
}

@IsTest
static void Nebula_WithDefined() {
	LoggerSettings__c orgDefaults = LoggerSettings__c.getOrgDefaults();
	orgDefaults.SystemLogMessageFormat__c = '{OriginLocation__c} -- {Message__c}';
	upsert orgDefaults;

	// outputs using the updated format (above)
	Logger.debug( 'Logging with custom system message format set in org default settings' );
}

The result is a different logger format for real debug logs vs. apex test debug logs.

Workarounds include creating this in every test class (in a @TestSetup method, maybe?)... or just living with the default log format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Layer: ConfigurationItems related to the custom hierarchy setting LoggerSettings__c or any included custom metadata typeLayer: Logger EngineItems related to the core logging engineType: BugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions