Skip to content

Commit ec2cfe8

Browse files
authored
Bugfix: entry save override is not always used (#857)
* Fixed #856 by adding new fields EntrySaveReason__c on LogEntryEvent__e & LogEntry__c to explicitly track why an entry is saved. This new field is now also used in LogEntryEventHandler.filterLogEntryEventsToSave() to ensure these types of entries are correctly saved in LogEntry__c.
1 parent ddd6b37 commit ec2cfe8

File tree

16 files changed

+198
-13
lines changed

16 files changed

+198
-13
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
The most robust observability solution for Salesforce experts. Built 100% natively on the platform, and designed to work seamlessly with Apex, Lightning Components, Flow, OmniStudio, and integrations.
77

8-
## Unlocked Package - v4.15.8
8+
## Unlocked Package - v4.15.9
99

10-
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015pFCQAY)
11-
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015pFCQAY)
10+
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015pGKQAY)
11+
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015pGKQAY)
1212
[![View Documentation](./images/btn-view-documentation.png)](https://github.com/jongpie/NebulaLogger/wiki)
1313

14-
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015pFCQAY`
14+
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015pGKQAY`
1515

1616
---
1717

nebula-logger/core.package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
<members>LogEntryEvent__e.DatabaseResultCollectionType__c</members>
146146
<members>LogEntryEvent__e.DatabaseResultJson__c</members>
147147
<members>LogEntryEvent__e.DatabaseResultType__c</members>
148+
<members>LogEntryEvent__e.EntrySaveReason__c</members>
148149
<members>LogEntryEvent__e.EntryScenario__c</members>
149150
<members>LogEntryEvent__e.EpochTimestamp__c</members>
150151
<members>LogEntryEvent__e.ExceptionLocation__c</members>
@@ -331,6 +332,7 @@
331332
<members>LogEntry__c.DatabaseResultCollectionType__c</members>
332333
<members>LogEntry__c.DatabaseResultJson__c</members>
333334
<members>LogEntry__c.DatabaseResultType__c</members>
335+
<members>LogEntry__c.EntrySaveReason__c</members>
334336
<members>LogEntry__c.EntryScenarioLink__c</members>
335337
<members>LogEntry__c.EntryScenarioName__c</members>
336338
<members>LogEntry__c.EntryScenarioText__c</members>

nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
8585
continue;
8686
}
8787

88-
if (String.isBlank(loggingUserSettings.DefaultPlatformEventStorageLoggingLevel__c)) {
89-
// DefaultPlatformEventStorageLoggingLevel__c is optional - if it's null, then always save the event
88+
// DefaultPlatformEventStorageLoggingLevel__c is optional - if it's null, then always save the event
89+
if (
90+
logEntryEvent.EntrySaveReason__c == LogEntryEventBuilder.ENTRY_SAVE_REASON_OVERRIDE ||
91+
String.isBlank(loggingUserSettings.DefaultPlatformEventStorageLoggingLevel__c)
92+
) {
9093
logEntryEventsToSave.add(logEntryEvent);
9194
} else {
9295
System.LoggingLevel userStorageLoggingLevel = System.LoggingLevel.valueOf(loggingUserSettings.DefaultPlatformEventStorageLoggingLevel__c);
@@ -272,6 +275,7 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
272275
DatabaseResultCollectionType__c = logEntryEvent.DatabaseResultCollectionType__c,
273276
DatabaseResultJson__c = logEntryEvent.DatabaseResultJson__c,
274277
DatabaseResultType__c = logEntryEvent.DatabaseResultType__c,
278+
EntrySaveReason__c = logEntryEvent.EntrySaveReason__c,
275279
EpochTimestamp__c = logEntryEvent.EpochTimestamp__c,
276280
EventUuid__c = logEntryEvent.EventUuid,
277281
ExceptionLocation__c = logEntryEvent.ExceptionLocation__c,

nebula-logger/core/main/log-management/flexipages/LogEntryRecordPage.flexipage-meta.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,29 @@
20682068
</visibilityRule>
20692069
</fieldInstance>
20702070
</itemInstances>
2071+
<itemInstances>
2072+
<fieldInstance>
2073+
<fieldInstanceProperties>
2074+
<name>uiBehavior</name>
2075+
<value>none</value>
2076+
</fieldInstanceProperties>
2077+
<fieldItem>Record.EntrySaveReason__c</fieldItem>
2078+
<identifier>RecordEntrySaveReason_cField</identifier>
2079+
<visibilityRule>
2080+
<booleanFilter>1 OR 2</booleanFilter>
2081+
<criteria>
2082+
<leftValue>{!Record.EntrySaveReason__c}</leftValue>
2083+
<operator>EQUAL</operator>
2084+
<rightValue>Logging Level Met</rightValue>
2085+
</criteria>
2086+
<criteria>
2087+
<leftValue>{!Record.EntrySaveReason__c}</leftValue>
2088+
<operator>EQUAL</operator>
2089+
<rightValue>Save Overridden</rightValue>
2090+
</criteria>
2091+
</visibilityRule>
2092+
</fieldInstance>
2093+
</itemInstances>
20712094
<itemInstances>
20722095
<fieldInstance>
20732096
<fieldInstanceProperties>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<fullName>EntrySaveReason__c</fullName>
4+
<businessStatus>Active</businessStatus>
5+
<complianceGroup>None</complianceGroup>
6+
<inlineHelpText>Indicates if entry was saved based on the logging user's settings, or based on a developer override in code</inlineHelpText>
7+
<label>Entry Save Reason</label>
8+
<required>false</required>
9+
<securityClassification>Confidential</securityClassification>
10+
<trackTrending>false</trackTrending>
11+
<type>Picklist</type>
12+
<valueSet>
13+
<valueSetDefinition>
14+
<sorted>false</sorted>
15+
<value>
16+
<fullName>Logging Level Met</fullName>
17+
<default>false</default>
18+
<label>Logging Level Met</label>
19+
</value>
20+
<value>
21+
<fullName>Save Overridden</fullName>
22+
<default>false</default>
23+
<label>Save Overridden</label>
24+
</value>
25+
</valueSetDefinition>
26+
</valueSet>
27+
</CustomField>

nebula-logger/core/main/log-management/permissionsets/LoggerAdmin.permissionset-meta.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@
266266
<field>LogEntry__c.DatabaseResultType__c</field>
267267
<readable>true</readable>
268268
</fieldPermissions>
269+
<fieldPermissions>
270+
<editable>false</editable>
271+
<field>LogEntry__c.EntrySaveReason__c</field>
272+
<readable>true</readable>
273+
</fieldPermissions>
269274
<fieldPermissions>
270275
<editable>false</editable>
271276
<field>LogEntry__c.EntryScenarioLink__c</field>

nebula-logger/core/main/log-management/permissionsets/LoggerEndUser.permissionset-meta.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@
117117
<field>LogEntry__c.DatabaseResultType__c</field>
118118
<readable>true</readable>
119119
</fieldPermissions>
120+
<fieldPermissions>
121+
<editable>false</editable>
122+
<field>LogEntry__c.EntrySaveReason__c</field>
123+
<readable>true</readable>
124+
</fieldPermissions>
120125
<fieldPermissions>
121126
<editable>false</editable>
122127
<field>LogEntry__c.EntryScenarioLink__c</field>

nebula-logger/core/main/log-management/permissionsets/LoggerLogViewer.permissionset-meta.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@
186186
<field>LogEntry__c.DatabaseResultType__c</field>
187187
<readable>true</readable>
188188
</fieldPermissions>
189+
<fieldPermissions>
190+
<editable>false</editable>
191+
<field>LogEntry__c.EntrySaveReason__c</field>
192+
<readable>true</readable>
193+
</fieldPermissions>
189194
<fieldPermissions>
190195
<editable>false</editable>
191196
<field>LogEntry__c.EntryScenarioLink__c</field>

nebula-logger/core/main/logger-engine/classes/LogEntryEventBuilder.cls

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
'PMD.AvoidGlobalModifier, PMD.CognitiveComplexity, PMD.CyclomaticComplexity, PMD.ExcessiveClassLength, PMD.ExcessivePublicCount, PMD.NcssTypeCount, PMD.PropertyNamingConventions, PMD.StdCyclomaticComplexity'
1313
)
1414
global with sharing class LogEntryEventBuilder {
15+
public static final String ENTRY_SAVE_REASON_LOGGING_LEVEL_MET = 'Logging Level Met';
16+
public static final String ENTRY_SAVE_REASON_OVERRIDE = 'Save Overridden';
17+
1518
private static final Map<String, String> CACHED_SOBJECT_NAME_TO_CLASSIFICATION = new Map<String, String>();
1619
private static final Schema.User CURRENT_USER = new Schema.User(Id = System.UserInfo.getUserId(), ProfileId = System.UserInfo.getProfileId());
1720
private static final String HTTP_HEADER_FORMAT = '{0}: {1}';
@@ -128,6 +131,7 @@ global with sharing class LogEntryEventBuilder {
128131
this.entryLoggingLevel = entryLoggingLevel;
129132

130133
this.logEntryEvent = getLogEntryEventTemplate(entryLoggingLevel);
134+
this.setSaveReason();
131135
this.setTimestamp(System.now());
132136
}
133137
}
@@ -848,6 +852,13 @@ global with sharing class LogEntryEventBuilder {
848852
return this.logEntryEvent;
849853
}
850854

855+
private void setSaveReason() {
856+
System.LoggingLevel userLoggingLevel = System.LoggingLevel.valueOf(this.userSettings.LoggingLevel__c);
857+
Boolean isEntryLoggingLevelEnabled = this.entryLoggingLevel.ordinal() >= userLoggingLevel.ordinal();
858+
859+
this.logEntryEvent.EntrySaveReason__c = isEntryLoggingLevelEnabled ? ENTRY_SAVE_REASON_LOGGING_LEVEL_MET : ENTRY_SAVE_REASON_OVERRIDE;
860+
}
861+
851862
@SuppressWarnings('PMD.AvoidDebugStatements')
852863
private void logToApexDebug(String message) {
853864
if (this.userSettings.IsApexSystemDebugLoggingEnabled__c == false) {
@@ -861,6 +872,7 @@ global with sharing class LogEntryEventBuilder {
861872
if (String.isBlank(possibleReplacement)) {
862873
continue;
863874
}
875+
864876
String logEntryFieldName = possibleReplacement.substringBefore('}');
865877
Object logEntryFieldValue = this.logEntryEvent.get(logEntryFieldName);
866878
if (logEntryFieldValue == null) {

nebula-logger/core/main/logger-engine/classes/Logger.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
global with sharing class Logger {
1616
// There's no reliable way to get the version number dynamically in Apex
1717
@TestVisible
18-
private static final String CURRENT_VERSION_NUMBER = 'v4.15.8';
18+
private static final String CURRENT_VERSION_NUMBER = 'v4.15.9';
1919
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
2020
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
2121
private static final String MISSING_SCENARIO_ERROR_MESSAGE = 'No logger scenario specified. A scenario is required for logging in this org.';
@@ -366,7 +366,7 @@ global with sharing class Logger {
366366
* @return Boolean
367367
*/
368368
global static Boolean meetsUserLoggingLevel(System.LoggingLevel logEntryLoggingLevel) {
369-
return userLoggingLevel.ordinal() <= logEntryLoggingLevel.ordinal();
369+
return logEntryLoggingLevel.ordinal() >= userLoggingLevel.ordinal();
370370
}
371371

372372
/**

0 commit comments

Comments
 (0)