Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more details in logger LWC's console statements #789

Merged
merged 3 commits into from
Nov 1, 2024

Conversation

jongpie
Copy link
Owner

@jongpie jongpie commented Oct 27, 2024

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 PR 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 (using setTimeout()) 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:

  1. 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.
  2. 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 (using new Date().toLocaleString()). This makes it a little easier for devs to troubleshoot exactly when an entry was generated in their browser.

image

@jongpie jongpie added Type: Enhancement New feature or request Logging Source: Lightning Components Items related to using Nebula Logger using JavaScript within lightning components (lwc & aura) Layer: Logger Engine Items related to the core logging engine labels Oct 27, 2024
@jongpie jongpie temporarily deployed to Advanced Scratch Org October 27, 2024 20:01 — with GitHub Actions Inactive
@jongpie jongpie temporarily deployed to Event Monitoring Scratch Org October 27, 2024 20:01 — with GitHub Actions Inactive
@jongpie
Copy link
Owner Author

jongpie commented Oct 27, 2024

@jamessimone if you have some time this week, I'd love to get your thoughts on these changes. I sent you an early preview of some of it a few days ago, but I've made several more tweaks to the output since then.

@jongpie jongpie requested a review from jamessimone October 27, 2024 20:07
@jongpie jongpie temporarily deployed to Platform Cache Scratch Org October 27, 2024 20:12 — with GitHub Actions Inactive
@jongpie jongpie temporarily deployed to Experience Cloud Scratch Org October 27, 2024 20:25 — with GitHub Actions Inactive
…'s printed using console statements

The stringified object now includes more details, such as the exception and tags

Calling the console function now happens with a delay (using setTimeout()) so that additional details can be added to the log entry (using the builder methods) before the log entry is stringified & printed out
@jongpie jongpie force-pushed the feature/improved-javascript-console-output branch from 5d0a72b to 711f81c Compare October 31, 2024 21:08
@jongpie jongpie temporarily deployed to Base Scratch Org October 31, 2024 21:12 — with GitHub Actions Inactive
@jongpie jongpie had a problem deploying to Advanced Scratch Org October 31, 2024 21:12 — with GitHub Actions Error
@jongpie jongpie temporarily deployed to Event Monitoring Scratch Org October 31, 2024 21:12 — with GitHub Actions Inactive
@jongpie jongpie temporarily deployed to OmniStudio Scratch Org October 31, 2024 21:24 — with GitHub Actions Inactive
@jongpie jongpie temporarily deployed to Platform Cache Scratch Org October 31, 2024 21:28 — with GitHub Actions Inactive
…messimone for the suggestion!), and updated some Jest asserts to match the updated output of some console statements
@jongpie jongpie force-pushed the feature/improved-javascript-console-output branch from 711f81c to 9aef5ba Compare October 31, 2024 22:19
@jongpie jongpie temporarily deployed to Event Monitoring Scratch Org October 31, 2024 22:24 — with GitHub Actions Inactive
@jongpie jongpie temporarily deployed to Advanced Scratch Org October 31, 2024 22:24 — with GitHub Actions Inactive
@jongpie jongpie temporarily deployed to Base Scratch Org October 31, 2024 22:24 — with GitHub Actions Inactive
@jongpie jongpie temporarily deployed to OmniStudio Scratch Org October 31, 2024 22:34 — with GitHub Actions Inactive
@jongpie jongpie temporarily deployed to Platform Cache Scratch Org October 31, 2024 22:37 — with GitHub Actions Inactive
@jongpie jongpie temporarily deployed to Experience Cloud Scratch Org October 31, 2024 22:46 — with GitHub Actions Inactive
Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 78.57143% with 6 lines in your changes missing coverage. Please review.

Project coverage is 92.72%. Comparing base (1707c41) to head (9aef5ba).

Files with missing lines Patch % Lines
...e/main/logger-engine/lwc/logger/logEntryBuilder.js 78.57% 2 Missing and 1 partial ⚠️
...ore/main/logger-engine/lwc/logger/loggerService.js 78.57% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #789      +/-   ##
==========================================
- Coverage   94.21%   92.72%   -1.50%     
==========================================
  Files          58       75      +17     
  Lines        5964     7283    +1319     
  Branches        0      200     +200     
==========================================
+ Hits         5619     6753    +1134     
- Misses        345      510     +165     
- Partials        0       20      +20     
Flag Coverage Δ
Apex 94.21% <ø> (ø)
LWC 85.97% <78.57%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jongpie jongpie merged commit e58b02f into main Nov 1, 2024
1 check passed
@jongpie jongpie deleted the feature/improved-javascript-console-output branch November 1, 2024 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Layer: Logger Engine Items related to the core logging engine Logging Source: Lightning Components Items related to using Nebula Logger using JavaScript within lightning components (lwc & aura) Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants