-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
New synchronous JS function getLogger() + deprecated async function createLogger() #775
Conversation
…chronously, and deprecated the async function createLogger() This simplifies how developers use the logger LWC, and avoids some lingering JS stack trace issues that occur in async functions The function createLogger() is still supported & functional, but it's now considered deprecated since it requires using 'await'
…d getLogger() function, and updated the existing demo LWC for the createLogger() function to indicate that it's now deprecated
115ee4d
to
8967ed2
Compare
One possibility that might help to clean things up in that test class such that you don't need to repeat yourself so much would be using parameterized tests:
In this example, each inner list passed to
What do you think? I will continue reviewing, but that might really help to cut down on the duplication in that file |
nebula-logger/core/main/logger-engine/lwc/logger/loggerService.js
Outdated
Show resolved
Hide resolved
nebula-logger/core/main/logger-engine/lwc/logger/loggerService.js
Outdated
Show resolved
Hide resolved
while (this.#taskQueue.length > 0) { | ||
const task = this.#taskQueue.shift(); | ||
task.output = task.actionFunction(...task.actionArguments); | ||
if (task.output instanceof Promise) { | ||
task.output = await task.output; | ||
} | ||
processedTasks.push(task); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want, you can slightly simplify this to:
/* eslint-disable no-await-in-loop */
this.#taskQueue.forEach(async task => {
task.output = await task.actionFunction(...task.actionArguments);
processedTasks.push(task);
});
this.#taskQueue = [];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh yeah, I like this, it seems much easier to read. For some reason, I thought I was having an issue with using await
for synchronous functions, so I added that instanceof
check, but seems unnecessary to use it.
And I typically do use forEach()
/ I generally don't use while
loops, so I'm trying to remember if there was some reason I used the while
loop in this case 🤔.... I think I was worried about situations where an async task is running & new sync tasks are enqueued while async is finishing. Something like...
- Some entries are added &
saveLog()
is called (async task) - While
saveLog()
is running, user takes some action, and another log entry is added to the task queue (beforesaveLog()
finishes)
In that situation, would the forEach()
function iterate over the newly-added task? I think I went with a while
loop to try to handle that situation - my thought was that the condition while (this.#taskQueue.length > 0)
would run at the end of each loop, and pick up any newly-enqueued tasks. I was worried forEach()
would only iterate over the values that were present in the array at the start of the iteration - but if forEach()
works just as well, I think your version is much more concise & easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right in saying that forEach()
would not iterate over a newly added task, but I guess I thought the #isProcessing
check would already prevent something from being added to the queue. Maybe a test for this is in order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think a test would be great - one of my worries with all of this is that some tasks will get skipped/accidentally dropped, resulting in data loss. I'll try to add a test - if you have any thoughts on how test for this, let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jongpie I left a few comments that I'd be curious to hear your thoughts on, especially the one for cleaning up logger.test.js
Overall this is looking good! Hopefully we can chat about all of this today
👀 Ooooh, yeah, I really like this idea, it's beautiful - I think this sounds like a much better approach. Before this PR, it already felt bad having two versions of the tests (one for With all that said, I might hold off on making this change right now, and instead do it in another PR in the coming weeks. There are several things related to Jest tests that I'd like to revisit:
I think I'll make another issue to cover all of the Jest stuff to improve in the repo (including using your approach above with |
That makes perfect sense! |
…parsing when lightning debug mode is disabled Previously, stack traces worked when debug mode was enabled, but was inaccurate when debug mode was off due to some subtle differences in the generated stack traces Also incorporated some code review feedback from @jamessimone Also removed opera stack trace parsing in loggerStackTrace.js - there was no test coverage for this, I haven't heard of anyone using Opera in years, and I just... don't want to have to test another browser. If/when someone says Opera support is needed, it can be revisited[D
3f25958
to
f43a62b
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
New
getLogger()
functionPartially fixed #728 by adding a new function
getLogger()
inlogger
LWC that can be called synchronously, and deprecated the async functioncreateLogger()
logger
LWC, and avoids some lingering JavaScript (JS) stack trace issues that occur inasync
functionscreateLogger()
is still supported & functional, but it's now considered deprecated since it requires usingawait
(which is no longer necessary withgetLogger()
)Note
This does not truly "fix" or improve the stack trace parsing used in
async
functions, andasync
functions will continue to have inaccurate function names reported in some browsers (typically,eval
is listed as the function name). This is a ongoing challenge in JavaScript due to what info is/isn't available in stack traces in some browsers (most notably, webkit browsers like Chrome & Edge).But with the new
getLogger()
function, Nebula Logger no longer requires the use ofasync
/await
- and often the only reason developers were usingasync
/await
was to be able to use Nebula Logger. In these situations, developers can eliminateasync
/await
, and the resulting log entries will have accurate JS function names.Example: Old
createLogger()
UsagePreviously, JS developers had to use
async
,await
, and truthy checks to ensure that Nebula Logger's LWC had finished being loaded. This resulted in more complexity for developers, who just want to be able to log some stuff 😢Example: New
getLogger()
UsageNow,
await
is no longer needed, and alogger
instance can be immediately initialized & used. This results in less code, and happier developers 🥳New
exception()
functionResolved #763 by adding a JS function equivalent to the Apex method
Logger.exception()
. Both of these do 3 things in 1 line of code:Previously in JS, this would have been 3 lines of code:
Now, 1 line of code provides the same functionality:
More Improvements for JS Stack Trace Parsing
Fixed #776 by updating logic in
loggerStackTrace.js
to better handle parsing when lightning debug mode is disabledPreviously, stack traces worked when debug mode was enabled, but was still inaccurate in some browsers when debug mode was off due to some subtle differences in the generated stack traces.