Skip to content

Commit

Permalink
Fixed #258 by adding 2 new fields to LoggerSettings__c (IsSavingEnabl…
Browse files Browse the repository at this point in the history
…ed__c and IsPlatformEventStorageEnabled__c), and further enhanced the refactor that @jamessimone helped with for loggerSettings - I've added another JS file, loggerSettingsPageLayout, to make it easier to manage/update the faux page layout via updating a JSON object (instead of updating/duplicating HTML)

Also cleaned up help text in several fields
  • Loading branch information
jongpie committed Jan 24, 2022
1 parent 81c25fe commit 1a9772f
Show file tree
Hide file tree
Showing 18 changed files with 430 additions and 318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<externalId>false</externalId>
<fieldManageability>SubscriberControlled</fieldManageability>
<inlineHelpText
>This value is used to set the field Log__c.LogRetentionDate__c, which is then used by LogBatchPurger to delete old logs. To keep logs indefinitely, set this field to blank (null).</inlineHelpText>
>This value is used to set the field Log__c.LogRetentionDate__c, which is then used by LogBatchPurger to delete old logs. To keep logs indefinitely, set this field to a blank value (null).</inlineHelpText>
<label>Days to Retain Logs</label>
<precision>4</precision>
<required>false</required>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@
<defaultValue>&apos;Read&apos;</defaultValue>
<description
>Uses Apex managed sharing to grants users read or edit access to their log records (on insert only). When no access level is specified, no Apex sharing logic is executed. This only gives record-level access - users will still need to be granted access to the Log__c object using permission sets or profiles.

Possible Values:
(blank)
Read
Edit</description>
</description>
<externalId>false</externalId>
<inlineHelpText
>Uses Apex managed sharing to grants users read or edit access to their log records (on insert only). When no access level is specified, no Apex sharing logic is executed. This only gives record-level access - users will still need to be granted access to the Log__c object using permission sets or profiles.

Possible Values:
(blank)
Read
Edit</inlineHelpText>
>Uses Apex managed sharing to grants users read or edit access to their log records (on insert only). When no access level is specified, no Apex sharing logic is executed. This only gives record-level access - users will still need to be granted access to the Log__c object using permission sets or profiles.</inlineHelpText>
<label>Log Access Level</label>
<length>255</length>
<required>false</required>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>DefaultSaveMethod__c</fullName>
<defaultValue>&apos;EVENT_BUS&apos;</defaultValue>
<description>Defaults to &apos;EVENT_BUS&apos;. This controls the default save method used by Logger when calling saveLog().

Possible values:
EVENT_BUS
QUEUEABLE
REST
SYNCHRONOUS_DML</description>
<description
>Defaults to EVENT_BUS. This controls the default save method used by Logger when calling saveLog(). In most situations, EVENT_BUS should be used.</description>
<externalId>false</externalId>
<inlineHelpText>Defaults to &apos;EVENT_BUS&apos;. This controls the default save method used by Logger when calling saveLog().

Possible values:
EVENT_BUS
QUEUEABLE
REST
SYNCHRONOUS_DML</inlineHelpText>
<inlineHelpText
>Defaults to EVENT_BUS. This controls the default save method used by Logger when calling saveLog(). In most situations, EVENT_BUS should be used.</inlineHelpText>
<label>Save Method</label>
<length>255</length>
<required>true</required>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
<fullName>IsAnonymousModeEnabled__c</fullName>
<defaultValue>false</defaultValue>
<externalId>false</externalId>
<inlineHelpText>When enabled, any logs generated will not have any user-specific details set - any fields related to the User, Profile, etc. will be null.

Note: this feature only works properly when using the save method EVENT_BUS.</inlineHelpText>
<inlineHelpText
>When enabled, any logs generated will not have any user-specific details set - any fields related to the User, Profile, etc. will be null. Note: this feature only works properly when using the save method EVENT_BUS.</inlineHelpText>
<label>Enable Anonymous Mode</label>
<trackTrending>false</trackTrending>
<type>Checkbox</type>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>IsPlatformEventStorageEnabled__c</fullName>
<defaultValue>true</defaultValue>
<description
>Controls if LogEntryEvent__e platform events are transformed &amp; stored in the custom objects Log__c and LogEntry__c (when IsSavingEnabled__c == true).</description>
<externalId>false</externalId>
<inlineHelpText
>Controls if LogEntryEvent__e platform events are transformed &amp; stored in the custom objects Log__c and LogEntry__c (when IsSavingEnabled__c == true).</inlineHelpText>
<label>Store Platform Events</label>
<type>Checkbox</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>IsSavingEnabled__c</fullName>
<defaultValue>true</defaultValue>
<description>Controls if saving is enabled - when disabled, any calls to saveLog() are ignored.</description>
<externalId>false</externalId>
<inlineHelpText>Controls if saving is enabled - when disabled, any calls to saveLog() are ignored.</inlineHelpText>
<label>Is Saving Enabled</label>
<type>Checkbox</type>
</CustomField>
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
<fullName>LoggingLevel__c</fullName>
<defaultValue>&apos;DEBUG&apos;</defaultValue>
<externalId>false</externalId>
<inlineHelpText>Possible values:
ERROR
WARN
INFO
DEBUG
FINE
FINER
FINEST</inlineHelpText>
<label>Logging Level</label>
<length>255</length>
<required>true</required>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
Log__c recentLogWithApiReleaseDetails = getRecentLogWithApiReleaseDetails();

for (LogEntryEvent__e logEntryEvent : this.logEntryEvents) {
// Load the logging user's settings
User loggingUser = new User(Id = logEntryEvent.LoggedById__c, ProfileId = logEntryEvent.ProfileId__c);
LoggerSettings__c loggingUserSettings = Logger.getUserSettings(loggingUser);
if (loggingUserSettings.IsPlatformEventStorageEnabled__c == false) {
continue;
}

// The LogEntryEvent__e object stores a denormalized version of Log__c & LogEntry__c data
// In case the list contains entries tied to multiple transactions, use the TRANSACTION_ID_TO_LOG map to create 1 Log__c per transaction ID
if (TRANSACTION_ID_TO_LOG.containsKey(logEntryEvent.TransactionId__c) == true) {
Expand Down Expand Up @@ -141,6 +148,12 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {

private void insertLogEntries() {
for (LogEntryEvent__e logEntryEvent : this.logEntryEvents) {
User loggingUser = new User(Id = logEntryEvent.LoggedById__c, ProfileId = logEntryEvent.ProfileId__c);
LoggerSettings__c loggingUserSettings = Logger.getUserSettings(loggingUser);
if (loggingUserSettings.IsPlatformEventStorageEnabled__c == false) {
continue;
}

// Workaround field for platform issue w/ accurate datetimes
Datetime timestamp = String.isNotBlank(logEntryEvent.TimestampString__c)
? Datetime.valueOf(Long.valueOf(logEntryEvent.TimestampString__c))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,30 +256,12 @@ public without sharing class LoggerSettingsController {
}

private static List<LoggerSettings__c> queryLoggerSettings() {
return [
SELECT
CreatedBy.Username,
CreatedById,
CreatedDate,
DefaultLogShareAccessLevel__c,
DefaultNumberOfDaysToRetainLogs__c,
DefaultSaveMethod__c,
Id,
IsAnonymousModeEnabled__c,
IsApexSystemDebugLoggingEnabled__c,
IsJavaScriptConsoleLoggingEnabled__c,
IsDataMaskingEnabled__c,
IsEnabled__c,
LastModifiedBy.Username,
LastModifiedById,
LastModifiedDate,
LoggingLevel__c,
SetupOwner.Name,
SetupOwner.Type,
SetupOwnerId,
StripInaccessibleRecordFields__c
FROM LoggerSettings__c
];
List<String> fieldNames = new List<String>(Schema.LoggerSettings__c.SObjectType.getDescribe().fields.getMap().keySet());
fieldNames.add('CreatedBy.Username');
fieldNames.add('LastModifiedBy.Username');
fieldNames.add('SetupOwner.Name');
fieldNames.add('SetupOwner.Type');
return (List<LoggerSettings__c>) Database.query('SELECT ' + String.join(fieldNames, ', ') + ' FROM ' + Schema.LoggerSettings__c.SObjectType);
}

private static Map<Id, String> querySetupOwnerNames(List<Id> setupOwnerIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,6 @@
"junctionReferenceTo": [],
"relationshipName": "FeedSubscriptionsForEntity"
},
{
"childObjectApiName": "NetworkActivityAudit",
"fieldName": "ParentEntityId",
"junctionIdListNames": [],
"junctionReferenceTo": [],
"relationshipName": "ParentEntities"
},
{
"childObjectApiName": "NetworkUserHistoryRecent",
"fieldName": "RecordId",
"junctionIdListNames": [],
"junctionReferenceTo": [],
"relationshipName": "NetworkUserHistoryRecentToRecord"
},
{
"childObjectApiName": "ProcessException",
"fieldName": "AttachedToId",
Expand Down Expand Up @@ -236,7 +222,7 @@
"filteredLookupInfo": null,
"highScaleNumber": false,
"htmlFormatted": false,
"inlineHelpText": "Uses Apex managed sharing to grants users read or edit access to their log records (on insert only). When no access level is specified, no Apex sharing logic is executed. This only gives record-level access - users will still need to be granted access to the Log__c object using permission sets or profiles.\n\nPossible Values:\n(blank)\nRead\nEdit",
"inlineHelpText": "Uses Apex managed sharing to grants users read or edit access to their log records (on insert only). When no access level is specified, no Apex sharing logic is executed. This only gives record-level access - users will still need to be granted access to the Log__c object using permission sets or profiles.",
"label": "Log Access Level",
"length": 255,
"nameField": false,
Expand Down Expand Up @@ -302,7 +288,7 @@
"filteredLookupInfo": null,
"highScaleNumber": false,
"htmlFormatted": false,
"inlineHelpText": "Defaults to 'EVENT_BUS'. This controls the default save method used by Logger when calling saveLog().\n\nPossible values:\nEVENT_BUS\nQUEUEABLE\nREST\nSYNCHRONOUS_DML",
"inlineHelpText": "Defaults to EVENT_BUS. This controls the default save method used by Logger when calling saveLog(). In most situations, EVENT_BUS should be used.",
"label": "Save Method",
"length": 255,
"nameField": false,
Expand Down Expand Up @@ -368,7 +354,7 @@
"filteredLookupInfo": null,
"highScaleNumber": false,
"htmlFormatted": false,
"inlineHelpText": "When enabled, any logs generated will not have any user-specific details set - any fields related to the User, Profile, etc. will be null.\n\nNote: this feature only works properly when using the save method EVENT_BUS.",
"inlineHelpText": "When enabled, any logs generated will not have any user-specific details set - any fields related to the User, Profile, etc. will be null. Note: this feature only works properly when using the save method EVENT_BUS.",
"label": "Enable Anonymous Mode",
"length": 0,
"nameField": false,
Expand Down Expand Up @@ -418,8 +404,8 @@
"unique": false,
"updateable": true
},
"IsJavaScriptConsoleLoggingEnabled__c": {
"apiName": "IsJavaScriptConsoleLoggingEnabled__c",
"IsDataMaskingEnabled__c": {
"apiName": "IsDataMaskingEnabled__c",
"calculated": false,
"compound": false,
"compoundComponentName": null,
Expand All @@ -434,8 +420,8 @@
"filteredLookupInfo": null,
"highScaleNumber": false,
"htmlFormatted": false,
"inlineHelpText": "When enabled, Logger will automatically call the browser's console.log() function when logging via lightning components. To help with performance, this option should be disabled in production unless you are actively troubleshooting an issue.",
"label": "Enable JavaScript console.log()",
"inlineHelpText": "When enabled, any data-mask rules (configured in LogEntryDataMaskRule__mdt) will be automatically applied to log entry messages.",
"label": "Enable Data Masking",
"length": 0,
"nameField": false,
"polymorphicForeignKey": false,
Expand All @@ -451,8 +437,41 @@
"unique": false,
"updateable": true
},
"IsDataMaskingEnabled__c": {
"apiName": "IsDataMaskingEnabled__c",
"IsDeleted": {
"apiName": "IsDeleted",
"calculated": false,
"compound": false,
"compoundComponentName": null,
"compoundFieldName": null,
"controllerName": null,
"controllingFields": [],
"createable": false,
"custom": false,
"dataType": "Boolean",
"extraTypeInfo": null,
"filterable": true,
"filteredLookupInfo": null,
"highScaleNumber": false,
"htmlFormatted": false,
"inlineHelpText": null,
"label": "Deleted",
"length": 0,
"nameField": false,
"polymorphicForeignKey": false,
"precision": 0,
"reference": false,
"referenceTargetField": null,
"referenceToInfos": [],
"relationshipName": null,
"required": true,
"scale": 0,
"searchPrefilterable": false,
"sortable": true,
"unique": false,
"updateable": false
},
"IsEnabled__c": {
"apiName": "IsEnabled__c",
"calculated": false,
"compound": false,
"compoundComponentName": null,
Expand All @@ -467,8 +486,8 @@
"filteredLookupInfo": null,
"highScaleNumber": false,
"htmlFormatted": false,
"inlineHelpText": "When enabled, any data-mask rules (configured in LogEntryDataMaskRule__mdt) will be automatically applied to log entry messages.",
"label": "Enable Data Masking",
"inlineHelpText": "Controls if Logger is enabled for the specified level (organization, profile, or user)",
"label": "Enabled",
"length": 0,
"nameField": false,
"polymorphicForeignKey": false,
Expand All @@ -484,24 +503,24 @@
"unique": false,
"updateable": true
},
"IsDeleted": {
"apiName": "IsDeleted",
"IsJavaScriptConsoleLoggingEnabled__c": {
"apiName": "IsJavaScriptConsoleLoggingEnabled__c",
"calculated": false,
"compound": false,
"compoundComponentName": null,
"compoundFieldName": null,
"controllerName": null,
"controllingFields": [],
"createable": false,
"custom": false,
"createable": true,
"custom": true,
"dataType": "Boolean",
"extraTypeInfo": null,
"filterable": true,
"filteredLookupInfo": null,
"highScaleNumber": false,
"htmlFormatted": false,
"inlineHelpText": null,
"label": "Deleted",
"inlineHelpText": "When enabled, Logger will automatically call the browser's console.log() function when logging via lightning components. To help with performance, this option should be disabled in production unless you are actively troubleshooting an issue.",
"label": "Enable JavaScript console.log()",
"length": 0,
"nameField": false,
"polymorphicForeignKey": false,
Expand All @@ -515,10 +534,10 @@
"searchPrefilterable": false,
"sortable": true,
"unique": false,
"updateable": false
"updateable": true
},
"IsEnabled__c": {
"apiName": "IsEnabled__c",
"IsPlatformEventStorageEnabled__c": {
"apiName": "IsPlatformEventStorageEnabled__c",
"calculated": false,
"compound": false,
"compoundComponentName": null,
Expand All @@ -533,8 +552,41 @@
"filteredLookupInfo": null,
"highScaleNumber": false,
"htmlFormatted": false,
"inlineHelpText": "Controls if Logger is enabled for the specified level (organization, profile, or user)",
"label": "Enabled",
"inlineHelpText": "Controls if LogEntryEvent__e platform events are transformed & stored in the custom objects Log__c and LogEntry__c (when IsSavingEnabled__c == true).",
"label": "Store Platform Events",
"length": 0,
"nameField": false,
"polymorphicForeignKey": false,
"precision": 0,
"reference": false,
"referenceTargetField": null,
"referenceToInfos": [],
"relationshipName": null,
"required": true,
"scale": 0,
"searchPrefilterable": false,
"sortable": true,
"unique": false,
"updateable": true
},
"IsSavingEnabled__c": {
"apiName": "IsSavingEnabled__c",
"calculated": false,
"compound": false,
"compoundComponentName": null,
"compoundFieldName": null,
"controllerName": null,
"controllingFields": [],
"createable": true,
"custom": true,
"dataType": "Boolean",
"extraTypeInfo": null,
"filterable": true,
"filteredLookupInfo": null,
"highScaleNumber": false,
"htmlFormatted": false,
"inlineHelpText": "Controls if saving is enabled - when disabled, any calls to saveLog() are ignored.",
"label": "Is Saving Enabled",
"length": 0,
"nameField": false,
"polymorphicForeignKey": false,
Expand Down Expand Up @@ -637,7 +689,7 @@
"filteredLookupInfo": null,
"highScaleNumber": false,
"htmlFormatted": false,
"inlineHelpText": "Possible values:\nERROR\nWARN\nINFO\nDEBUG\nFINE\nFINER\nFINEST",
"inlineHelpText": null,
"label": "Logging Level",
"length": 255,
"nameField": false,
Expand Down
Loading

0 comments on commit 1a9772f

Please sign in to comment.