Skip to content

Commit

Permalink
Added more fields on LogEntryEvent__e, Log__c, and LogEntry__c (#503)
Browse files Browse the repository at this point in the history
* Renamed (created new) Log__c fields ApiVersion__c, ApiReleaseNumber__c and ApiReleaseVersion__c to OrganizationApiVersion__c, OrganizationReleaseNumber__c and OrganizationReleaseVersion__c,

* Added new field Log__c.OrganizationLocation__c

* Added extra test & guard clause in LogEntryHandler to handle scenarios where OriginLocation__c is not a valid Flow API name

* Added new Flow fields on LogEntry__c FlowRecordTriggerType__c, FlowTriggerOrder__c, and FlowTriggerSObjectType__c

* Added new fields on LogEntry__c to track details about the user's browser

* Updated logEntryBuilder.js and jest tests to internally use a new function, getComponentLogEntry(). This makes the JavaScript code (logEntryBuilder.js + ComponentLogEntry) better align with the Apex equivalent code (LogEntryEventBuilder and LogEntryEvent__e)

* Removed some old references in LoggerHomeHeaderController to now-removed properties on Logger.StatusApiResponse
  • Loading branch information
jongpie authored Jun 5, 2023
1 parent 8db89d0 commit 36f7440
Show file tree
Hide file tree
Showing 62 changed files with 1,313 additions and 272 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
test-coverage/
temp/

# Additional folders that are temporarily copied when creating a version of the managed package
nebula-logger/managed-package/core/main/configuration/
nebula-logger/managed-package/core/main/log-management/
nebula-logger/managed-package/core/main/logger-engine/
nebula-logger/managed-package/core/tests/

# NPM
node_modules/
yarn.lock
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

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

## Unlocked Package - v4.10.5
## Unlocked Package - v4.10.6

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

`sfdx package install --wait 20 --security-type AdminsOnly --package 04t5Y0000023SCHQA2`
`sfdx package install --wait 20 --security-type AdminsOnly --package 04t5Y0000023SCqQAM`

## Managed Package - v4.10.0

Expand Down
2 changes: 1 addition & 1 deletion config/linters/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@lwc/lwc/no-attributes-during-construction": "error",
"@lwc/lwc/no-deprecated": "error",
"@lwc/lwc/no-document-query": "error",
"@lwc/lwc/no-dupe-class-members": "error",
"@lwc/lwc/no-dupe-class-members": "warn",
"@lwc/lwc/no-inner-html": "error",
"@lwc/lwc/no-leading-uppercase-api-name": "error",
"@lwc/lwc/prefer-custom-event": "error",
Expand Down
9 changes: 5 additions & 4 deletions config/linters/lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ module.exports = {
'*.{cls,cmp,component,css,html,js,json,md,page,trigger,yaml,yml}': filenames => filenames.map(filename => `prettier --write '${filename}'`),
'**/lwc/**': filenames => {
return [`eslint --config ./config/linters/.eslintrc.json ${filenames.join(' ')} --fix`, `npm run test:lwc`];
},
'*.{cls,trigger}': () => {
return [`npm run scan:apex`];
// return [`npm run scan:apex`, `npm run docs:fix && git add ./docs/ && git commit --amend --no-edit`];
}
// FIXME this command should only scan the changed Apex files (instead of scanning all Apex files)
// '*.{cls,trigger}': () => {
// return [`npm run scan:apex`];
// // return [`npm run scan:apex`, `npm run docs:fix && git add ./docs/ && git commit --amend --no-edit`];
// }
};
28 changes: 14 additions & 14 deletions docs/apex/Log-Management/LogBatchPurgeController.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ Boolean

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

#### `getBatchPurgeJobRecords()``List<AsyncApexJob>`

Returns `List&lt;AsyncApexJob&gt;` to display logBatchPurger jobs details in a Datatable.

##### Return

**Type**

List&lt;AsyncApexJob&gt;

**Description**

The instance of `List&lt;AsyncApexJob&gt;`, containing list of logBatchPurge jobs.

#### `getMetrics(String dateFilterOption)``Map<String, Object>`

return a `Map&lt;String,Object&gt;` contains metrics for number of `Log__c`, `LogEntry__c`, `LogEntryTag__c` records to purge, for the given timeframe TODAY/ THIS_WEEK/ THIS_MONTH. The metrics is grouped by `Log__c.LogPurgeAction__c`.
Expand Down Expand Up @@ -58,20 +72,6 @@ List&lt;PicklistOption&gt;

The instance of `List&lt;PicklistOption&gt;`, containing all picklist options for purge Action.

#### `getBatchPurgeJobRecords()``List<AsyncApexJob>`

Returns `List&lt;AsyncApexJob&gt;` to display logBatchPurger jobs details in a Datatable.

##### Return

**Type**

List&lt;AsyncApexJob&gt;

**Description**

The instance of `List&lt;AsyncApexJob&gt;`, containing list of logBatchPurge jobs.

#### `runBatchPurge()``String`

execute the logBatchPurger batch with batch size 2000
Expand Down
24 changes: 24 additions & 0 deletions docs/apex/Logger-Engine/ComponentLogger.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ A DTO object used to create log entries for lightning components

##### Properties

###### `browserFormFactor``String`

The form factor of the user&apos;s browser

###### `browserLanguage``String`

The language set in the user&apos;s browser

###### `browserScreenResolution``String`

The resolution of the user&apos;s device

###### `browserUrl``String`

The URL displayed in the user&apos;s browser

###### `browserUserAgent``String`

The user agent of the user&apos;s browser

###### `browserWindowResolution``String`

The resolution of the user&apos;s browser window

###### `error``ComponentError`

(Optional) A JavaScript Error to log
Expand Down
4 changes: 0 additions & 4 deletions docs/apex/Logger-Engine/Logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -5628,8 +5628,6 @@ Asynchronoulsy publishes the list of `LogEntryEvent__e` records

Boolean used when saving records. If true, all records must save correctly or an exception is thrown. If false, partial processing is enabled, and if an indidividual record fails, successful records are still saved without exception.

###### `environment``String`

###### `location``String`

###### `maintenanceWindow``String`
Expand All @@ -5642,8 +5640,6 @@ List of records to save.

###### `releaseVersion``String`

###### `status``String`

---

##### Methods
Expand Down
10 changes: 10 additions & 0 deletions docs/lightning-components/LogEntryBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [.setError(error)](#LogEntryBuilder+setError) [<code>LogEntryBuilder</code>](#LogEntryBuilder)
- [.addTag(tag)](#LogEntryBuilder+addTag) [<code>LogEntryBuilder</code>](#LogEntryBuilder)
- [.addTags(tags)](#LogEntryBuilder+addTags) [<code>LogEntryBuilder</code>](#LogEntryBuilder)
- [.getComponentLogEntry()](#LogEntryBuilder+getComponentLogEntry) <code>ComponentLogEntry</code>

<a name="new_LogEntryBuilder_new"></a>

Expand Down Expand Up @@ -102,3 +103,12 @@ Appends the tag to the existing list of tags
| Param | Type | Description |
| ----- | --------------------------------- | -------------------------------------------------------- |
| tags | <code>Array.&lt;String&gt;</code> | The list of strings to add as tags for the current entry |

<a name="LogEntryBuilder+getComponentLogEntry"></a>

### logEntryBuilder.getComponentLogEntry() <code>ComponentLogEntry</code>

Returns the object used to save log entry data

**Kind**: instance method of [<code>LogEntryBuilder</code>](#LogEntryBuilder)
**Returns**: <code>ComponentLogEntry</code> - An instance of `ComponentLogEntry` that matches the Apex class `ComponentLogger.ComponentLogEntry`
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
}

Log__c log = new Log__c(
// TODO Log__c.ApiReleaseNumber__c and Log__c.ApiReleaseVersion__c are both deprecated,
// in a future release, remove these reference (and delete the fields)
ApiReleaseNumber__c = recentLogWithApiReleaseDetails?.ApiReleaseNumber__c,
ApiReleaseVersion__c = recentLogWithApiReleaseDetails?.ApiReleaseVersion__c,
// TODO Log__c.ApiVersion__c and LogEntryEvent__e.ApiVersion__c are both deprecated,
// in a future release, remove this reference (and delete the fields)
ApiVersion__c = logEntryEvent.ApiVersion__c,
ImpersonatedBy__c = logEntryEvent.ImpersonatedById__c,
Locale__c = logEntryEvent.Locale__c,
Expand All @@ -162,12 +166,15 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
NetworkName__c = logEntryEvent.NetworkName__c,
NetworkSelfRegistrationUrl__c = logEntryEvent.NetworkSelfRegistrationUrl__c,
NetworkUrlPathPrefix__c = logEntryEvent.NetworkUrlPathPrefix__c,
OrganizationApiVersion__c = logEntryEvent.OrganizationApiVersion__c,
OrganizationDomainUrl__c = logEntryEvent.OrganizationDomainUrl__c,
OrganizationEnvironmentType__c = logEntryEvent.OrganizationEnvironmentType__c,
OrganizationId__c = logEntryEvent.OrganizationId__c,
OrganizationInstanceName__c = logEntryEvent.OrganizationInstanceName__c,
OrganizationName__c = logEntryEvent.OrganizationName__c,
OrganizationNamespacePrefix__c = logEntryEvent.OrganizationNamespacePrefix__c,
OrganizationReleaseNumber__c = recentLogWithApiReleaseDetails?.OrganizationReleaseNumber__c,
OrganizationReleaseVersion__c = recentLogWithApiReleaseDetails?.OrganizationReleaseVersion__c,
OrganizationType__c = logEntryEvent.OrganizationType__c,
OwnerId = this.determineLogOwnerId(logEntryEvent),
ParentLogTransactionId__c = logEntryEvent.ParentLogTransactionId__c,
Expand Down Expand Up @@ -244,6 +251,12 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
}

LogEntry__c logEntry = new LogEntry__c(
BrowserFormFactor__c = logEntryEvent.BrowserFormFactor__c,
BrowserLanguage__c = logEntryEvent.BrowserLanguage__c,
BrowserScreenResolution__c = logEntryEvent.BrowserScreenResolution__c,
BrowserUrl__c = logEntryEvent.BrowserUrl__c,
BrowserUserAgent__c = logEntryEvent.BrowserUserAgent__c,
BrowserWindowResolution__c = logEntryEvent.BrowserWindowResolution__c,
ComponentType__c = logEntryEvent.ComponentType__c,
DatabaseResultCollectionSize__c = logEntryEvent.DatabaseResultCollectionSize__c,
DatabaseResultCollectionType__c = logEntryEvent.DatabaseResultCollectionType__c,
Expand Down Expand Up @@ -692,14 +705,14 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
WHERE Id IN :this.logIds AND ApiReleaseNumber__c = NULL
LIMIT :System.Limits.getLimitDmlRows()
]) {
// TODO Logger.ApiResponse has new properties that aren't currently being captured here,
// so in a future release, add new custom fields to capture more (all?) properties
// - environment
// - location
// - maintenanceWindow
// ✔ releaseNumber
// ✔ releaseVersion
// - status
log.OrganizationLocation__c = statusApiResponse.location;
log.OrganizationReleaseNumber__c = statusApiResponse.releaseNumber;
log.OrganizationReleaseVersion__c = statusApiResponse.releaseVersion;

// TODO ApiReleaseNumber__c and ApiReleaseVersion__c are deprecated as of v4.10.6
// For now, they're still set so orgs have time to migrate to the new fields, but in
// a future release, ApiReleaseNumber__c and ApiReleaseVersion__c should be completely
// remove from the codebase
log.ApiReleaseNumber__c = statusApiResponse.releaseNumber;
log.ApiReleaseVersion__c = statusApiResponse.releaseVersion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,20 @@ public without sharing class LogEntryHandler extends LoggerSObjectHandler {

for (LogEntry__c logEntry : flowLogEntries) {
FlowDefinitionView flowDefinition = flowApiNameToDefinition.get(logEntry.OriginLocation__c);
if (flowDefinition == null) {
continue;
}

logEntry.FlowActiveVersionId__c = flowDefinition.ActiveVersionId;
logEntry.FlowDescription__c = flowDefinition.Description;
logEntry.FlowDurableId__c = flowDefinition.DurableId;
logEntry.FlowLabel__c = flowDefinition.Label;
logEntry.FlowLastModifiedByName__c = flowDefinition.LastModifiedBy;
logEntry.FlowLastModifiedDate__c = flowDefinition.LastModifiedDate;
logEntry.FlowProcessType__c = flowDefinition.ProcessType;
logEntry.FlowRecordTriggerType__c = flowDefinition.RecordTriggerType;
logEntry.FlowTriggerOrder__c = flowDefinition.TriggerOrder;
logEntry.FlowTriggerSObjectType__c = flowDefinition.TriggerObjectOrEvent?.QualifiedApiName;
logEntry.FlowTriggerType__c = flowDefinition.TriggerType;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public without sharing virtual class LogManagementDataSelector {
Datetime fourHoursAgo = System.now().addMinutes(-4 * 60);

List<Log__c> logs = [
SELECT Id, ApiReleaseNumber__c, ApiReleaseVersion__c
SELECT Id, ApiReleaseNumber__c, ApiReleaseVersion__c, OrganizationReleaseNumber__c, OrganizationReleaseVersion__c
FROM Log__c
WHERE CreatedDate >= :fourHoursAgo AND CreatedDate = TODAY AND ApiReleaseNumber__c != NULL
ORDER BY CreatedDate DESC
Expand Down Expand Up @@ -162,7 +162,11 @@ public without sharing virtual class LogManagementDataSelector {
LastModifiedDate,
ManageableState,
ProcessType,
TriggerType
RecordTriggerType,
TriggerObjectOrEvent.QualifiedApiName,
TriggerOrder,
TriggerType,
VersionNumber
FROM FlowDefinitionView
WHERE ApiName IN :flowApiNames AND IsActive = TRUE
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ public without sharing class LoggerHomeHeaderController {

Logger.StatusApiResponse statusApiResponse = Logger.callStatusApi();
if (statusApiResponse != null) {
environment.organizationEnvironment = statusApiResponse.environment;
environment.organizationInstanceLocation = statusApiResponse.location;
environment.organizationMaintenanceWindow = statusApiResponse.maintenanceWindow;
environment.organizationReleaseNumber = statusApiResponse.releaseNumber;
environment.organizationReleaseVersion = statusApiResponse.releaseVersion;
environment.organizationStatus = statusApiResponse.status;

if (statusApiResponse.Products != null && statusApiResponse.Products.isEmpty() == false) {
environment.organizationInstanceProducts = getInstanceProductNames(statusApiResponse);
Expand Down Expand Up @@ -66,8 +64,6 @@ public without sharing class LoggerHomeHeaderController {
@AuraEnabled
public String organizationDomainUrl = 'Unknown';
@AuraEnabled
public String organizationEnvironment = 'Unknown';
@AuraEnabled
public String organizationFormattedCreatedDate = 'Unknown';
@AuraEnabled
public String organizationId = 'Unknown';
Expand All @@ -86,8 +82,6 @@ public without sharing class LoggerHomeHeaderController {
@AuraEnabled
public String organizationReleaseVersion = 'Unknown';
@AuraEnabled
public String organizationStatus = 'Unknown';
@AuraEnabled
public String organizationType = 'Unknown';
}
}
Loading

0 comments on commit 36f7440

Please sign in to comment.