-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More controls for scenario-based logging (#357)
* Closed #347 & #356 by deprecating LogScenarioRule__mdt object & replacing it with a new object LoggerScenarioRule__mdt that provides optional overrides for all fields on LoggerSettings__c * Added new Apex class LogScenarioRule to manage accessing LoggerScenarioRule__mdt CMDT records * Incorporated the stellar idea from @jamessimone to tie LogEntry__c records to the new LoggerScenario__c object via a new lookup field LogEntry__c.EntryScenario__c * Added new method Logger.endScenario(String) so that Apex developers can explicitly end a scenario, which then automatically rolls back to the previous scenario (and re-applies the previous scenario rule, if one exists) - another fantastic suggestion from @jamessimone * Renamed LoggerSettings__c.DefaultLogScenario__c to LoggerSettings__c.DefaultScenario__c for consistency * Fixed #360 by changing Logger.logDatabaseErrors() overloads to always return a non-null instance of LogEntryEventBuilder * Updated some formatting in SlackLoggerPlugin to better format stack traces & create new plugin package version v1.5.0 * Fixed #363 by correcting some references in the migration script ./scripts/data/migrate-log-scenario-field-to-logger-scenario-object.apex * Added content in README that links to the wiki's architecture overview * Removed build numbers for package versions in sfdx-project.json, upgraded some packages in package.json to resolve some GitHub security alerts
- Loading branch information
Showing
85 changed files
with
1,854 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
layout: default | ||
--- | ||
|
||
## LoggerScenarioRule class | ||
|
||
Provides a centralized way to load scenario rules that override behavior within Nebula Logger | ||
|
||
--- | ||
|
||
### Methods | ||
|
||
#### `getAll()` → `Map<String, LoggerScenarioRule_t>` | ||
|
||
Returns a map containing any enabled `LoggerScenarioRule_t` records with valid `StartTime__c` and `EndTime__c` values (null is considered valid) | ||
|
||
##### Return | ||
|
||
**Type** | ||
|
||
Map<String, LoggerScenarioRule_t> | ||
|
||
**Description** | ||
|
||
The current transaction's cached `Map<String, LoggerScenarioRule_t>`, where the key | ||
|
||
#### `getInstance(String scenario)` → `LoggerScenarioRule_t` | ||
|
||
Returns the `LoggerScenarioRule_t` with the matching scenario, based on the field `LoggerScenarioRule_t.Scenario__c` | ||
|
||
##### Parameters | ||
|
||
| Param | Description | | ||
| ---------- | ------------------------ | | ||
| `scenario` | The name of the scenario | | ||
|
||
##### Return | ||
|
||
**Type** | ||
|
||
LoggerScenarioRule_t | ||
|
||
**Description** | ||
|
||
The matching `LoggerScenarioRule_t` if one is found, or `null` | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
nebula-logger/core/main/configuration/classes/LoggerScenarioRule.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//------------------------------------------------------------------------------------------------// | ||
// This file is part of the Nebula Logger project, released under the MIT License. // | ||
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. // | ||
//------------------------------------------------------------------------------------------------// | ||
|
||
/** | ||
* @group Configuration | ||
* @description Provides a centralized way to load scenario rules that override behavior | ||
* within Nebula Logger | ||
*/ | ||
public without sharing class LoggerScenarioRule { | ||
private static final Map<String, LoggerScenarioRule__mdt> SCENARIO_NAME_TO_SCENARIO_RULE = loadLogScenarioRules(); | ||
|
||
/** | ||
* @description Returns a map containing any enabled `LoggerScenarioRule__mdt` records with | ||
* valid `StartTime__c` and `EndTime__c` values (null is considered valid) | ||
* @return The current transaction's cached `Map<String, LoggerScenarioRule__mdt>`, where the key | ||
* is the log scenario (configured in `LoggerScenarioRule__mdt.Scenario__c`) | ||
*/ | ||
public static Map<String, LoggerScenarioRule__mdt> getAll() { | ||
return SCENARIO_NAME_TO_SCENARIO_RULE; | ||
} | ||
|
||
/** | ||
* @description Returns the `LoggerScenarioRule__mdt` with the matching scenario, | ||
* based on the field `LoggerScenarioRule__mdt.Scenario__c` | ||
* @param scenario The name of the scenario | ||
* @return The matching `LoggerScenarioRule__mdt` if one is found, or `null` | ||
*/ | ||
public static LoggerScenarioRule__mdt getInstance(String scenario) { | ||
return SCENARIO_NAME_TO_SCENARIO_RULE.get(scenario); | ||
} | ||
|
||
@TestVisible | ||
private static void setMock(LoggerScenarioRule__mdt scenarioRule) { | ||
if (String.isBlank(scenarioRule.Scenario__c) == true) { | ||
throw new IllegalArgumentException('Scenario__c is required on `LoggerScenarioRule__mdt: \n' + JSON.serializePretty(scenarioRule)); | ||
} | ||
|
||
if (isValid(scenarioRule) == true) { | ||
SCENARIO_NAME_TO_SCENARIO_RULE.put(scenarioRule.Scenario__c, scenarioRule); | ||
} | ||
} | ||
|
||
private static Map<String, LoggerScenarioRule__mdt> loadLogScenarioRules() { | ||
Map<String, LoggerScenarioRule__mdt> scenarioRules = new Map<String, LoggerScenarioRule__mdt>(); | ||
for (LoggerScenarioRule__mdt scenarioRule : LoggerScenarioRule__mdt.getAll().values()) { | ||
if (isValid(scenarioRule) == true) { | ||
scenarioRules.put(scenarioRule.Scenario__c, scenarioRule); | ||
} | ||
} | ||
|
||
if (System.Test.isRunningTest() == true) { | ||
scenarioRules.clear(); | ||
} | ||
|
||
return scenarioRules; | ||
} | ||
|
||
private static Boolean isValid(LoggerScenarioRule__mdt scenarioRule) { | ||
Boolean isValid = false; | ||
if (scenarioRule.IsEnabled__c == true) { | ||
Datetime currentTime = System.now(); | ||
Boolean startTimeIsValid = scenarioRule.StartTime__c == null || scenarioRule.StartTime__c <= currentTime; | ||
Boolean endTimeIsValid = scenarioRule.EndTime__c == null || scenarioRule.EndTime__c >= currentTime; | ||
|
||
isValid = startTimeIsValid == true && endTimeIsValid == true; | ||
} | ||
return isValid; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
nebula-logger/core/main/configuration/classes/LoggerScenarioRule.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>55.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
164 changes: 164 additions & 0 deletions
164
...configuration/layouts/LoggerScenarioRule__mdt-Logger Scenario Rule Layout.layout-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<Layout xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<layoutSections> | ||
<customLabel>false</customLabel> | ||
<detailHeading>true</detailHeading> | ||
<editHeading>true</editHeading> | ||
<label>Information</label> | ||
<layoutColumns> | ||
<layoutItems> | ||
<behavior>Required</behavior> | ||
<field>MasterLabel</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Required</behavior> | ||
<field>DeveloperName</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Required</behavior> | ||
<field>Scenario__c</field> | ||
</layoutItems> | ||
</layoutColumns> | ||
<layoutColumns> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>IsEnabled__c</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>StartTime__c</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>EndTime__c</field> | ||
</layoutItems> | ||
</layoutColumns> | ||
<style>TwoColumnsTopToBottom</style> | ||
</layoutSections> | ||
<layoutSections> | ||
<customLabel>true</customLabel> | ||
<detailHeading>true</detailHeading> | ||
<editHeading>true</editHeading> | ||
<label>Logger Engine Overrides</label> | ||
<layoutColumns> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>IsLoggerEnabled__c</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>UserLoggingLevel__c</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>IsSavingEnabled__c</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>SaveMethod__c</field> | ||
</layoutItems> | ||
</layoutColumns> | ||
<layoutColumns> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>IsAnonymousModeEnabled__c</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>IsApexSystemDebugLoggingEnabled__c</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>IsJavaScriptConsoleLoggingEnabled__c</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>IsDataMaskingEnabled__c</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>IsRecordFieldStrippingEnabled__c</field> | ||
</layoutItems> | ||
</layoutColumns> | ||
<style>TwoColumnsTopToBottom</style> | ||
</layoutSections> | ||
<layoutSections> | ||
<customLabel>true</customLabel> | ||
<detailHeading>true</detailHeading> | ||
<editHeading>true</editHeading> | ||
<label>Log Management Overrides</label> | ||
<layoutColumns> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>IsPlatformEventStorageLocationEnabled__c</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>PlatformEventStorageLocation__c</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>IsLogAssignmentEnabled__c</field> | ||
</layoutItems> | ||
</layoutColumns> | ||
<layoutColumns> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>IsLogRetentionOverrideEnabled__c</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>NumberOfDaysToRetainLogs__c</field> | ||
</layoutItems> | ||
</layoutColumns> | ||
<style>TwoColumnsTopToBottom</style> | ||
</layoutSections> | ||
<layoutSections> | ||
<customLabel>false</customLabel> | ||
<detailHeading>true</detailHeading> | ||
<editHeading>true</editHeading> | ||
<label>System Information</label> | ||
<layoutColumns> | ||
<layoutItems> | ||
<behavior>Required</behavior> | ||
<field>NamespacePrefix</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Readonly</behavior> | ||
<field>CreatedById</field> | ||
</layoutItems> | ||
</layoutColumns> | ||
<layoutColumns> | ||
<layoutItems> | ||
<behavior>Edit</behavior> | ||
<field>IsProtected</field> | ||
</layoutItems> | ||
<layoutItems> | ||
<behavior>Readonly</behavior> | ||
<field>LastModifiedById</field> | ||
</layoutItems> | ||
</layoutColumns> | ||
<style>TwoColumnsTopToBottom</style> | ||
</layoutSections> | ||
<layoutSections> | ||
<customLabel>true</customLabel> | ||
<detailHeading>true</detailHeading> | ||
<editHeading>false</editHeading> | ||
<label>Custom Links</label> | ||
<layoutColumns /> | ||
<layoutColumns /> | ||
<layoutColumns /> | ||
<style>CustomLinks</style> | ||
</layoutSections> | ||
<showEmailCheckbox>false</showEmailCheckbox> | ||
<showHighlightsPanel>false</showHighlightsPanel> | ||
<showInteractionLogPanel>false</showInteractionLogPanel> | ||
<showRunAssignmentRulesCheckbox>false</showRunAssignmentRulesCheckbox> | ||
<showSubmitAndAttachButton>false</showSubmitAndAttachButton> | ||
<summaryLayout> | ||
<masterLabel>00h63000007CAvC</masterLabel> | ||
<sizeX>4</sizeX> | ||
<sizeY>0</sizeY> | ||
<summaryLayoutStyle>Default</summaryLayoutStyle> | ||
</summaryLayout> | ||
</Layout> |
4 changes: 2 additions & 2 deletions
4
..._mdt/LogScenarioRule__mdt.object-meta.xml → ...t/LoggerScenarioRule__mdt.object-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<label>Log Scenario Rule</label> | ||
<pluralLabel>Log Scenario Rules</pluralLabel> | ||
<label>Logger Scenario Rule</label> | ||
<pluralLabel>Logger Scenario Rules</pluralLabel> | ||
<visibility>Public</visibility> | ||
</CustomObject> |
Oops, something went wrong.