Skip to content

Commit

Permalink
Cleaned up a few more code inconsistencies found during code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jongpie committed Jun 1, 2023
1 parent 128fdc7 commit 157b2d1
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 45 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public without sharing class LogEntryHandler extends LoggerSObjectHandler {
logEntry.FlowProcessType__c = flowDefinition.ProcessType;
logEntry.FlowRecordTriggerType__c = flowDefinition.RecordTriggerType;
logEntry.FlowTriggerOrder__c = flowDefinition.TriggerOrder;
logEntry.FlowTriggerSObjectType__c = flowDefinition.TriggerObjectOrEvent.QualifiedApiName;
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 @@ -528,7 +528,7 @@ describe('logger lwc legacy markup tests', () => {
expect(secondLogEntry.scenario).toBeNull();
expect(logger.getBufferSize()).toEqual(2);

const scenario = 'some scenario';
const scenario = 'another scenario';
logger.setScenario(scenario);

expect(firstLogEntry.scenario).toEqual(scenario);
Expand Down
49 changes: 24 additions & 25 deletions nebula-logger/core/main/logger-engine/lwc/logger/logEntryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ const ComponentLogEntry = class {
};

const LogEntryBuilder = class {
logEntry;

#componentLogEntry;
#settingsPromise;

/**
Expand All @@ -39,7 +38,7 @@ const LogEntryBuilder = class {
* @param {Boolean} isConsoleLoggingEnabled Determines if `console.log()` methods are execute
*/
constructor(loggingLevel, settingsPromise) {
this.logEntry = new ComponentLogEntry(loggingLevel);
this.#componentLogEntry = new ComponentLogEntry(loggingLevel);
this.#settingsPromise = settingsPromise;

this._setBrowserDetails();
Expand All @@ -51,7 +50,7 @@ const LogEntryBuilder = class {
* @return {LogEntryBuilder} The same instance of `LogEntryBuilder`, useful for chaining methods
*/
setMessage(message) {
this.logEntry.message = message;
this.#componentLogEntry.message = message;
this._logToConsole();
return this;
}
Expand All @@ -62,7 +61,7 @@ const LogEntryBuilder = class {
* @return {LogEntryBuilder} The same instance of `LogEntryBuilder`, useful for chaining methods
*/
setRecordId(recordId) {
this.logEntry.recordId = recordId;
this.#componentLogEntry.recordId = recordId;
return this;
}

Expand All @@ -72,7 +71,7 @@ const LogEntryBuilder = class {
* @return {LogEntryBuilder} The same instance of `LogEntryBuilder`, useful for chaining methods
*/
setRecord(record) {
this.logEntry.record = record;
this.#componentLogEntry.record = record;
return this;
}

Expand All @@ -82,15 +81,15 @@ const LogEntryBuilder = class {
* @return {LogEntryBuilder} The same instance of `LogEntryBuilder`, useful for chaining methods
*/
setError(error) {
this.logEntry.error = {};
this.#componentLogEntry.error = {};
if (error.body) {
this.logEntry.error.message = error.body.message;
this.logEntry.error.stack = error.body.stackTrace;
this.logEntry.error.type = error.body.exceptionType;
this.#componentLogEntry.error.message = error.body.message;
this.#componentLogEntry.error.stack = error.body.stackTrace;
this.#componentLogEntry.error.type = error.body.exceptionType;
} else {
this.logEntry.error.message = error.message;
this.logEntry.error.stack = error.stack;
this.logEntry.error.type = 'JavaScript.' + error.name;
this.#componentLogEntry.error.message = error.message;
this.#componentLogEntry.error.stack = error.stack;
this.#componentLogEntry.error.type = 'JavaScript.' + error.name;
}
return this;
}
Expand All @@ -101,9 +100,9 @@ const LogEntryBuilder = class {
* @return {LogEntryBuilder} The same instance of `LogEntryBuilder`, useful for chaining methods
*/
addTag(tag) {
this.logEntry.tags.push(tag);
this.#componentLogEntry.tags.push(tag);
// Deduplicate the list of tags
this.logEntry.tags = Array.from(new Set(this.logEntry.tags));
this.#componentLogEntry.tags = Array.from(new Set(this.#componentLogEntry.tags));
return this;
}

Expand All @@ -124,16 +123,16 @@ const LogEntryBuilder = class {
* @return {ComponentLogEntry} An instance of `ComponentLogEntry` that matches the Apex class `ComponentLogger.ComponentLogEntry`
*/
getComponentLogEntry() {
return this.logEntry;
return this.#componentLogEntry;
}

_setBrowserDetails() {
this.logEntry.browserFormFactor = FORM_FACTOR;
this.logEntry.browserLanguage = window.navigator.language;
this.logEntry.browserScreenResolution = window.screen.availWidth + ' x ' + window.screen.availHeight;
this.logEntry.browserUrl = window.location.href;
this.logEntry.browserUserAgent = window.navigator.userAgent;
this.logEntry.browserWindowResolution = window.innerWidth + ' x ' + window.innerHeight;
this.#componentLogEntry.browserFormFactor = FORM_FACTOR;
this.#componentLogEntry.browserLanguage = window.navigator.language;
this.#componentLogEntry.browserScreenResolution = window.screen.availWidth + ' x ' + window.screen.availHeight;
this.#componentLogEntry.browserUrl = window.location.href;
this.#componentLogEntry.browserUserAgent = window.navigator.userAgent;
this.#componentLogEntry.browserWindowResolution = window.innerWidth + ' x ' + window.innerHeight;
}

/* eslint-disable no-console */
Expand Down Expand Up @@ -163,12 +162,12 @@ const LogEntryBuilder = class {
break;
}

consoleLoggingFunction(consoleMessagePrefix, consoleFormatting, this.logEntry.message);
console.groupCollapsed(consoleMessagePrefix, consoleFormatting, 'Details for: ' + this.logEntry.message);
consoleLoggingFunction(consoleMessagePrefix, consoleFormatting, this.#componentLogEntry.message);
console.groupCollapsed(consoleMessagePrefix, consoleFormatting, 'Details for: ' + this.#componentLogEntry.message);
// The use of JSON.parse(JSON.stringify()) is intended to help ensure that the output is readable,
// including handling proxy objects. If any cyclic objects are used, this approach could fail
consoleLoggingFunction(JSON.parse(JSON.stringify(this)));
console.trace();
// console.trace();
console.groupEnd();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const LoggerService = class {
}
const loggingPromise = this._loadSettingsFromServer().then(() => {
if (this._meetsUserLoggingLevel(loggingLevel) === true) {
this.#componentLogEntries.push(logEntryBuilder.logEntry);
this.#componentLogEntries.push(logEntryBuilder.getComponentLogEntry());
}
});
this.#loggingPromises.push(loggingPromise);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,18 @@ private class LogManagementDataSelector_Tests {
LoggerTestConfigurator.setupMockSObjectHandlerConfigurations();
LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.Log__c.SObjectType).IsEnabled__c = false;
Log__c olderLog = new Log__c(
ApiReleaseNumber__c = 'QWERTY',
ApiReleaseVersion__c = 'ASDF',
OrganizationReleaseNumber__c = 'QWERTY',
OrganizationReleaseVersion__c = 'ASDF',
TransactionId__c = 'ABC'
ApiReleaseNumber__c = 'olderLog.ApiReleaseNumber__c',
ApiReleaseVersion__c = 'olderLog.ApiReleaseVersion__c',
OrganizationReleaseNumber__c = 'olderLog.OrganizationReleaseNumber__c',
OrganizationReleaseVersion__c = 'olderLog.OrganizationReleaseVersion__c',
TransactionId__c = 'olderLog.TransactionId__c'
);
Log__c expectedLog = new Log__c(
ApiReleaseNumber__c = 'QWERTY',
ApiReleaseVersion__c = 'ASDF',
OrganizationReleaseNumber__c = 'QWERTY',
OrganizationReleaseVersion__c = 'ASDF',
TransactionId__c = 'XYZ'
ApiReleaseNumber__c = 'expectedLog.ApiReleaseNumber__c',
ApiReleaseVersion__c = 'expectedLog.ApiReleaseVersion__c',
OrganizationReleaseNumber__c = 'expectedLog.OrganizationReleaseNumber__c',
OrganizationReleaseVersion__c = 'expectedLog.OrganizationReleaseVersion__c',
TransactionId__c = 'expectedLog.TransactionId__c'
);
insert new List<Log__c>{ olderLog, expectedLog };
System.Test.setCreatedDate(olderLog.Id, System.now().addMinutes(-5));
Expand Down

0 comments on commit 157b2d1

Please sign in to comment.