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

✨ Even better logging #140

Merged
merged 18 commits into from
Jan 22, 2021
Merged

✨ Even better logging #140

merged 18 commits into from
Jan 22, 2021

Conversation

wwilsman
Copy link
Contributor

@wwilsman wwilsman commented Jan 21, 2021

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, and debug 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.

@wwilsman wwilsman added the ✨ enhancement New feature or request label Jan 21, 2021
@wwilsman wwilsman force-pushed the ww/better-logging branch 9 times, most recently from a3d88c6 to 7a01de5 Compare January 21, 2021 23:38
@wwilsman wwilsman force-pushed the ww/better-logging branch 4 times, most recently from 86ecae4 to 9bfb11a Compare January 22, 2021 01:26
@wwilsman wwilsman added the 💥 breaking Breaking change label Jan 22, 2021
@wwilsman wwilsman marked this pull request as ready for review January 22, 2021 01:31
Base automatically changed from ww/no-puppeteer to master January 22, 2021 17:38
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.
@Robdel12
Copy link
Contributor

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.

🔥 This is exactly what we've been chasing for ages. Can't wait

Copy link
Contributor

@Robdel12 Robdel12 left a 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');
Copy link
Contributor

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) {
Copy link
Contributor

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();
Copy link
Contributor

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 😂

Copy link
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💥 breaking Breaking change ✨ enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants