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 bd5b4c2
Show file tree
Hide file tree
Showing 17 changed files with 336 additions and 281 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 @@ -269,7 +269,7 @@
"filteredLookupInfo": null,
"highScaleNumber": false,
"htmlFormatted": false,
"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).",
"label": "Days to Retain Logs",
"length": 0,
"nameField": false,
Expand Down
Loading

0 comments on commit bd5b4c2

Please sign in to comment.