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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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. Current state: how it looks prior to this PR...
    • 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. Future state: how it looks with this PR's changes...
    • 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

…'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 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 temporarily deployed to Platform Cache Scratch Org October 27, 2024 20:12 — with GitHub Actions Inactive
Copy link

codecov bot commented Oct 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.21%. Comparing base (68c4187) to head (5d0a72b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #789      +/-   ##
==========================================
+ Coverage   92.79%   94.21%   +1.42%     
==========================================
  Files          75       58      -17     
  Lines        7229     5929    -1300     
  Branches      191        0     -191     
==========================================
- Hits         6708     5586    -1122     
+ Misses        502      343     -159     
+ Partials       19        0      -19     
Flag Coverage Δ
Apex 94.21% <ø> (-0.02%) ⬇️
LWC ?

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 temporarily deployed to Experience Cloud Scratch Org October 27, 2024 20:25 — with GitHub Actions Inactive
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.

1 participant