Added more details in logger LWC's console statements
Core Unlocked Package Changes
When using the logger
LWC and JavaScript console logging is enabled (via LoggerSettings__c.IsJavaScriptConsoleLoggingEnabled__c
), Nebula Logger automatically calls functions in the browser's console
so devs can easily see the generated log entry directly in their browser (instead of having to find it in LogEntry__c
). This release improves the component log entry JSON that's printed using console
statements - the stringified object now includes more details, such as details about the logged error/exception (when an error is logged), any tags added to the entry, and the user's localized version of the entry's timestamp
.
- This includes a change to how Nebula Logger internally calls the browser's
console
functions: now,console
functions are called with a 1 second delay (usingsetTimeout()
) so that additional details can be added to the log entry (using the builder methods) before the log entry is stringified & printed out. This may not be a perfect solution, but seems to work in most cases of using the JS builder methods.
To show the difference in the changes, this JavaScript was used to generate some example log entries:
this.logger.setScenario('Some demo scenario')
const someError = new TypeError('oops');
this.logger.error('Hello, world!')
.setExceptionDetails(someError)
.setField({ SomeLogEntryField__c: 'some text from loggerLWCGetLoggerImportDemo' })
.addTags(['Tag-one', 'Another tag here']);
In the screenshot below, 2 versions of the output are shown:
- Before:
- No details are included in the output about the error, the tags, or the custom field mappings.
- The timestamp is only shown in UTC.
- After:
- The output now includes details about any errors/exceptions logged using the builder function
setExceptionDetails()
.- Previously the output only included the logged message - no details were included about the logged exception/error, which made it much harder to troubleshoot whatever the relevant error was 🙃
- The error output includes details about the metadata source, making it easy to tell if the error was caused by another LWC, an Apex controller method, or an Apex trigger.
- When devs use any of Nebula Logger's optional JS features (scenarios, tags, and custom field mappings), the details are automatically included in the
console
statements' output - For devs that do not leverage these optional features, the relevant properties are automatically excluded from the
console
output. This keeps the output slimmer & easier to read. - Each entry's timestamp is now shown both in UTC time (using
new Date().toISOString()
) and in the user's local format (usingnew Date().toLocaleString()
). This makes it a little easier for devs to troubleshoot exactly when an entry was generated in their browser.
- The output now includes details about any errors/exceptions logged using the builder function
Installation Info
Core Unlocked Package - no namespace
Full Changelog: v4.14.16...v4.14.17
- SF CLI:
sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015ocRQAQ
- SFDX CLI:
sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y0000015ocRQAQ
- Sandbox: https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015ocRQAQ
- Production: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015ocRQAQ