-
Notifications
You must be signed in to change notification settings - Fork 41
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
✨ Even better logging #140
Conversation
a3d88c6
to
7a01de5
Compare
802d23b
to
c91588a
Compare
86ecae4
to
9bfb11a
Compare
9bfb11a
to
b1392ef
Compare
For logging purposes, these functions are better off not as helpers due to how specific they are to a page and its assocated capture or snapshot information
With additional logging, it became evident that the page was being closed during navigation. This is handled by a navigation timeout, however that timeout is too long to account for in this test. The test has been adjusted to help ensure navigation is finished when closing.
b1392ef
to
2ddd967
Compare
🔥 This is exactly what we've been chasing for ages. Can't wait |
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.
This is doppe! Super excited for this. I noticed the README wasn't updated, so we'll want to do that for docs/usage/etc
log.warn('Warning: `percy-agent.js` is deprecated, please update to the latest SDK version'); | ||
|
||
let wrapper = '(window.PercyAgent = class PercyAgent { snapshot(n, o) { return PercyDOM.serialize(o); } });'; | ||
log.deprecated('`percy-agent.js` is deprecated, please update to the latest SDK version'); |
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.
log.deprecated
🔥 😍 hnngg
} | ||
|
||
// Ensures that deprecation messages are not logged more than once | ||
deprecated(debug, message, meta) { |
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 love this so much.
} | ||
|
||
// timestamp each log | ||
let timestamp = Date.now(); |
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.
It's nice to see my cruft go away 😂
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.
🏁
Purpose
With #128, we have much deeper control and insight into the asset discovery process. While the current logs are pretty good, this PR revamps the internal logger to make them even better so we can utilize them going forward in debugging customer issues.
While Winston is a great logger with many features, we only use a few; and with those few, not to their full potential. For example, formatters and transports – we use a custom formatter to add a percy label and color log levels, and we two transports for console logging and file logging. However, we still patch a few methods to better fit our use cases.
Approach
Replace Winston entirely with a custom logger. This custom logger follows a familiar loglevel style with
info
,warn
,error
, anddebug
log levels, but additionally follows a traditional Node debug style format that allows precise control of which debug logs to show. This enables us to sprinkle more and more logs throughout the codebase while maintaining and easily digestible, granular, format.The new logger also drops the file logger completely and instead opts to retain in-memory logs so that they may be queried and uploaded later. If necessary, we can still save these full logs to a file using pipes which could then be inspected post-mortem.
The previous logger test helper captured all process IO writes which could cause the runner output itself to be swallowed if something went wrong during capture. The new logger test helper is linked directly to the logger's in-memory store which allows other processes to continue writing to stdio without interruption. This additionally required a slight modification of existing stdio writes to utilize the logger's stdio which is mocked under testing.
The
@percy/sdk-utils
package had it's own logger and log test helper to avoid including Winston's entire ecosystem in individual SDKs. Now that Winston and its dependencies are removed, we can include our own logger and its helper within that package. This does mean that consuming SDKs will need to be updated to the new logging style as well to be compatible with this beta.As an experiment to test the value of these new logs, I tracked down and fixed a flakey test that consistently failed more often than not on my machine. It required a slight refactor of the capture method, but once additional logs were added, it became clear what the issue was and was substantially easier to fix.