Skip to content

Commit

Permalink
New Logger Parameter records to control storage locations for scenari…
Browse files Browse the repository at this point in the history
…o & tag data (#422)

* Added declarative changes to make it configurable if scenarios or tags are stored in custom objects (default) or text fields (which can help with data skew issues in orgs with large data volumes) - this is controlled by the 2 new LoggerParamemter__mdt records 'NormalizeScenarioData' and 'NormalizeTagData'

* Added code changes to control where scenario & tag data is stored, based on the new LoggerParameter__mdt records
  • Loading branch information
jongpie authored Dec 8, 2022
1 parent 3317ac8 commit 4814f4e
Show file tree
Hide file tree
Showing 33 changed files with 526 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/fetch-repo-stats.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: Fetch Repo Stats

on:
schedule:
# Run this once per day, towards the end of the day for keeping the most
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.

## Unlocked Package - v4.9.8
## Unlocked Package - v4.9.9

[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000023RBBQA2)
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000023RBBQA2)
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000023RBpQAM)
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000023RBpQAM)
[![View Documentation](./images/btn-view-documentation.png)](https://jongpie.github.io/NebulaLogger/)

## Managed Package - v4.9.0
Expand Down
10 changes: 9 additions & 1 deletion docs/apex/Configuration/LoggerParameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ Indicates if Nebula Logger will append its own log entries about the logging sys

Indicates if Nebula Logger's tagging system is enabled. Controlled by the custom metadata record `LoggerParameter.EnableTagging`, or `true` as the default

#### `NORMALIZE_SCENARIO_DATA``Boolean`

Indicates if Nebula Logger will store scenarios in the custom object `LoggerScenario__c`, or in the fields `Log__c.TransactionScenarioName__c` & `LogEntry__c.EntryScenario__c`. Controlled by the custom metadata record `LoggerParameter.NormalizeScenarioData`, or `true` as the default

#### `NORMALIZE_TAG_DATA``Boolean`

Indicates if Nebula Logger will store tags in the custom objects `LoggerTag__c` & `LogEntryTag__c`, or in the field `LogEntry__c.Tags__c`. Controlled by the custom metadata record `LoggerParameter.NormalizeTagData`, or `true` as the default

#### `PLATFORM_CACHE_PARTITION_NAME``String`

The name of the Platform Cache partition to use for caching (when platform cache is enabled). Controlled by the custom metadata record `LoggerParameter.PlatformCachePartitionName`, or `LoggerCache` as the default
Expand Down Expand Up @@ -76,7 +84,7 @@ Indicates if Nebula Logger queries `User` data is queried synchronously & po

#### `SEND_ERROR_EMAIL_NOTIFICATIONS``Boolean`

Indicates if Logger will send an error email notification if any internal exceptions occur. Controlled by the custom metadata record `LoggerParameter.SendErrorEmailNotifications`, or `true` as the default
Indicates if Nebula Logger will send an error email notification if any internal exceptions occur. Controlled by the custom metadata record `LoggerParameter.SendErrorEmailNotifications`, or `true` as the default

#### `SYSTEM_DEBUG_MESSAGE_FORMAT``String`

Expand Down
4 changes: 2 additions & 2 deletions docs/apex/Log-Management/LogBatchPurgeController.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Controller class for lwc `logBatchPurge`, used to provide metrics of `Log__c`, `

### Methods

#### `canUserRunLogBatchPurger()``boolean`
#### `canUserRunLogBatchPurger()``Boolean`

Returns true if the current user has delete permission on the Log\_\_c object or

##### Return

**Type**

boolean
Boolean

**Description**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,36 @@ public class LoggerParameter {
private set;
}

/**
* @description Indicates if Nebula Logger will store scenarios in the custom object `LoggerScenario__c`,
* or in the fields `Log__c.TransactionScenarioName__c` & `LogEntry__c.EntryScenario__c`.
* Controlled by the custom metadata record `LoggerParameter.NormalizeScenarioData`, or `true` as the default
*/
public static final Boolean NORMALIZE_SCENARIO_DATA {
get {
if (NORMALIZE_SCENARIO_DATA == null) {
NORMALIZE_SCENARIO_DATA = getBoolean('NormalizeScenarioData', true);
}
return NORMALIZE_SCENARIO_DATA;
}
private set;
}

/**
* @description Indicates if Nebula Logger will store tags in the custom objects `LoggerTag__c` & `LogEntryTag__c`,
* or in the field `LogEntry__c.Tags__c`.
* Controlled by the custom metadata record `LoggerParameter.NormalizeTagData`, or `true` as the default
*/
public static final Boolean NORMALIZE_TAG_DATA {
get {
if (NORMALIZE_TAG_DATA == null) {
NORMALIZE_TAG_DATA = getBoolean('NormalizeTagData', true);
}
return NORMALIZE_TAG_DATA;
}
private set;
}

/**
* @description The name of the Platform Cache partition to use for caching (when platform cache is enabled).
* Controlled by the custom metadata record `LoggerParameter.PlatformCachePartitionName`, or `LoggerCache` as the default
Expand Down Expand Up @@ -257,7 +287,7 @@ public class LoggerParameter {
}

/**
* @description Indicates if Logger will send an error email notification if any internal exceptions occur.
* @description Indicates if Nebula Logger will send an error email notification if any internal exceptions occur.
* Controlled by the custom metadata record `LoggerParameter.SendErrorEmailNotifications`, or `true` as the default
*/
public static final Boolean SEND_ERROR_EMAIL_NOTIFICATIONS {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomMetadata
xmlns="http://soap.sforce.com/2006/04/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<label>Normalize Scenario Data</label>
<protected>false</protected>
<values>
<field>Description__c</field>
<value
xsi:type="xsd:string"
>When set to &apos;true&apos; (default), any scenarios specified via Logger.setScenario() will be stored in the custom object LoggerScenario__c.

When set to &apos;false&apos;, scenarios are only stored in the text fields Log__c.TransactionScenarioName__c and LogEntry__c.EntryScenarioName__c</value>
</values>
<values>
<field>Value__c</field>
<value xsi:type="xsd:string">true</value>
</values>
</CustomMetadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomMetadata
xmlns="http://soap.sforce.com/2006/04/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<label>Normalize Tag Data</label>
<protected>false</protected>
<values>
<field>Description__c</field>
<value
xsi:type="xsd:string"
>When set to &apos;true&apos; (default), any tags specified via LogEntryEventBuilder.addTag() or LogEntryEventBuilder.addTags() will be stored in the custom objects LogEntryTag__c and LoggerTag__c.

When set to &apos;false&apos;, tags are only stored in the long text area field LogEntry__c.Tags__c.</value>
</values>
<values>
<field>Value__c</field>
<value xsi:type="xsd:string">true</value>
</values>
</CustomMetadata>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<field>Description__c</field>
<value xsi:type="xsd:string">Note: this parameter only applies to orgs that are using Experience Cloud (Communities).

When set to &apos;true&apos; (default), the Network object will be queried to track additional details about the logging user's Network when they are logged in via an Experience Cloud Site - the queried data is stored in fields on LogEntryEvent__e and Log__c.
When set to &apos;true&apos; (default), the Network object will be queried to track additional details about the logging user&apos;s Network when they are logged in via an Experience Cloud Site - the queried data is stored in fields on LogEntryEvent__e and Log__c.

When set to &apos;false&apos;, the Network object will not be queried, and the related fields will be null.</value>
</values>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {

if (String.isBlank(scenario) == true || SCENARIO_UNIQUE_ID_TO_SCENARIO.containsKey(scenario)) {
continue;
} else if (LoggerParameter.NORMALIZE_SCENARIO_DATA == true) {
LoggerScenario__c loggerScenario = new LoggerScenario__c(Name = scenario, UniqueId__c = scenario);
loggerScenario.setOptions(DML_OPTIONS);
SCENARIO_UNIQUE_ID_TO_SCENARIO.put(loggerScenario.UniqueId__c, loggerScenario);
}

LoggerScenario__c loggerScenario = new LoggerScenario__c(Name = scenario, UniqueId__c = scenario);
loggerScenario.setOptions(DML_OPTIONS);
SCENARIO_UNIQUE_ID_TO_SCENARIO.put(loggerScenario.UniqueId__c, loggerScenario);
}
}

Expand Down Expand Up @@ -181,6 +181,10 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
UserType__c = logEntryEvent.UserType__c
);

if (LoggerParameter.NORMALIZE_SCENARIO_DATA == false) {
log.TransactionScenarioName__c = logEntryEvent.TransactionScenario__c;
}

if (
String.isNotBlank(logEntryEvent.TransactionScenario__c) == true &&
SCENARIO_UNIQUE_ID_TO_SCENARIO.containsKey(logEntryEvent.TransactionScenario__c) == true
Expand Down Expand Up @@ -307,11 +311,16 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
TriggerSObjectType__c = logEntryEvent.TriggerSObjectType__c
);

if (
String.isNotBlank(logEntryEvent.EntryScenario__c) == true &&
SCENARIO_UNIQUE_ID_TO_SCENARIO.containsKey(logEntryEvent.EntryScenario__c) == true
) {
logEntry.EntryScenario__c = SCENARIO_UNIQUE_ID_TO_SCENARIO.get(logEntryEvent.EntryScenario__c).Id;
if (String.isNotBlank(logEntryEvent.EntryScenario__c) == true) {
if (LoggerParameter.NORMALIZE_SCENARIO_DATA == true && SCENARIO_UNIQUE_ID_TO_SCENARIO.containsKey(logEntryEvent.EntryScenario__c) == true) {
logEntry.EntryScenario__c = SCENARIO_UNIQUE_ID_TO_SCENARIO.get(logEntryEvent.EntryScenario__c).Id;
} else {
logEntry.EntryScenarioName__c = logEntryEvent.EntryScenario__c;
}
}

if (String.isNotBlank(logEntryEvent.Tags__c) == true && LoggerParameter.NORMALIZE_TAG_DATA == false) {
logEntry.Tags__c = logEntryEvent.Tags__c;
}

logEntry.setOptions(DML_OPTIONS);
Expand Down Expand Up @@ -358,7 +367,7 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
}

private void upsertLogEntryTags() {
if (LoggerParameter.ENABLE_TAGGING == false || this.tagNames.isEmpty() == true) {
if (LoggerParameter.ENABLE_TAGGING == false || LoggerParameter.NORMALIZE_TAG_DATA == false || this.tagNames.isEmpty() == true) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public without sharing class LogEntryHandler extends LoggerSObjectHandler {
// So, this code handles maintaing some checkbox fields via Apex instead
for (LogEntry__c logEntry : this.logEntries) {
logEntry.HasExceptionStackTrace__c = logEntry.ExceptionStackTrace__c != null;
logEntry.HasInlineTags__c = logEntry.Tags__c != null;
logEntry.HasRecordJson__c = logEntry.RecordJson__c != null;
logEntry.HasStackTrace__c = logEntry.StackTrace__c != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,34 @@
<name>main</name>
<type>Region</type>
</flexiPageRegions>
<flexiPageRegions>
<itemInstances>
<fieldInstance>
<fieldInstanceProperties>
<name>uiBehavior</name>
<value>none</value>
</fieldInstanceProperties>
<fieldItem>Record.Tags__c</fieldItem>
<identifier>RecordTags_cField</identifier>
</fieldInstance>
</itemInstances>
<name>Facet-1ea06e42-55f6-41d8-8bc9-52c13cd5dcd2</name>
<type>Facet</type>
</flexiPageRegions>
<flexiPageRegions>
<itemInstances>
<componentInstance>
<componentInstanceProperties>
<name>body</name>
<value>Facet-1ea06e42-55f6-41d8-8bc9-52c13cd5dcd2</value>
</componentInstanceProperties>
<componentName>flexipage:column</componentName>
<identifier>flexipage_column16</identifier>
</componentInstance>
</itemInstances>
<name>Facet-defe921e-2975-4026-bfa5-1fe30baba592</name>
<type>Facet</type>
</flexiPageRegions>
<flexiPageRegions>
<itemInstances>
<fieldInstance>
Expand Down Expand Up @@ -1285,6 +1313,27 @@
<identifier>force_relatedListSingleContainer</identifier>
</componentInstance>
</itemInstances>
<itemInstances>
<componentInstance>
<componentInstanceProperties>
<name>columns</name>
<value>Facet-defe921e-2975-4026-bfa5-1fe30baba592</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>Tags</value>
</componentInstanceProperties>
<componentName>flexipage:fieldSection</componentName>
<identifier>flexipage_fieldSection11</identifier>
<visibilityRule>
<criteria>
<leftValue>{!Record.HasInlineTags__c}</leftValue>
<operator>EQUAL</operator>
<rightValue>true</rightValue>
</criteria>
</visibilityRule>
</componentInstance>
</itemInstances>
<itemInstances>
<componentInstance>
<componentInstanceProperties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@
<name>uiBehavior</name>
<value>readonly</value>
</fieldInstanceProperties>
<fieldItem>Record.TransactionScenario__c</fieldItem>
<identifier>RecordTransactionScenario__cField</identifier>
<fieldItem>Record.TransactionScenarioLink__c</fieldItem>
<identifier>RecordTransactionScenarioLink__cField</identifier>
</fieldInstance>
</itemInstances>
<itemInstances>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>EntryScenario__c</field>
<field>EntryScenarioLink__c</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
<field>TransactionScenario__c</field>
<field>TransactionScenarioLink__c</field>
</layoutItems>
<layoutItems>
<behavior>Readonly</behavior>
Expand Down Expand Up @@ -369,7 +369,7 @@
<fields>Origin__c</fields>
<fields>Message__c</fields>
<fields>RecordDetailedLink__c</fields>
<fields>EntryScenario__c</fields>
<fields>EntryScenarioLink__c</fields>
<fields>LoggingLevelWithImage__c</fields>
<fields>TransactionEntryNumber__c</fields>
<relatedList>LogEntry__c.Log__c</relatedList>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>EntryScenarioLink__c</fullName>
<externalId>false</externalId>
<formula>IF(
ISBLANK(EntryScenario__c),
EntryScenarioName__c,
HYPERLINK(
'/' + EntryScenario__c,
EntryScenario__r.Name,
&apos;_top&apos;
)
)</formula>
<formulaTreatBlanksAs>BlankAsZero</formulaTreatBlanksAs>
<label>Entry Scenario</label>
<required>false</required>
<trackTrending>false</trackTrending>
<type>Text</type>
<unique>false</unique>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>EntryScenarioName__c</fullName>
<businessStatus>Active</businessStatus>
<complianceGroup>None</complianceGroup>
<externalId>false</externalId>
<label>Entry Scenario Name</label>
<length>255</length>
<required>false</required>
<securityClassification>Confidential</securityClassification>
<trackFeedHistory>false</trackFeedHistory>
<trackTrending>false</trackTrending>
<type>Text</type>
<unique>false</unique>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>HasInlineTags__c</fullName>
<businessStatus>Active</businessStatus>
<complianceGroup>None</complianceGroup>
<defaultValue>false</defaultValue>
<externalId>false</externalId>
<label>Has Inline Tags</label>
<securityClassification>Confidential</securityClassification>
<trackFeedHistory>false</trackFeedHistory>
<trackTrending>false</trackTrending>
<type>Checkbox</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Tags__c</fullName>
<businessStatus>Active</businessStatus>
<complianceGroup>None</complianceGroup>
<externalId>false</externalId>
<label>Tags</label>
<length>131072</length>
<securityClassification>Confidential</securityClassification>
<trackFeedHistory>false</trackFeedHistory>
<trackHistory>false</trackHistory>
<trackTrending>false</trackTrending>
<type>LongTextArea</type>
<visibleLines>8</visibleLines>
</CustomField>
Loading

0 comments on commit 4814f4e

Please sign in to comment.