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

Replace console.log with structured logging #508

Open
wants to merge 42 commits into
base: main
Choose a base branch
from

Conversation

LewisBroadhurst
Copy link

@LewisBroadhurst LewisBroadhurst commented Mar 30, 2024

Closes #399

Winston logger has been used to replace the console.log() node logging in the git-proxy application. Logs generated from git-proxy use now have a format of [timestamp] [log level]: [log message], and can be found in the files git-proxy.log and error.log under the src/logging directory.

Before merging, I wanted to confirm that the old console.log() lines should be removed also. Maybe they are useful in some cases?

Copy link

linux-foundation-easycla bot commented Mar 30, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

netlify bot commented Mar 30, 2024

Deploy Preview for endearing-brigadeiros-63f9d0 canceled.

Name Link
🔨 Latest commit 059e76f
🔍 Latest deploy log https://app.netlify.com/sites/endearing-brigadeiros-63f9d0/deploys/660851c7e8761b000853721f

Copy link

netlify bot commented Mar 30, 2024

Deploy Preview for endearing-brigadeiros-63f9d0 ready!

Name Link
🔨 Latest commit 520c5a5
🔍 Latest deploy log https://app.netlify.com/sites/endearing-brigadeiros-63f9d0/deploys/663e1b7bbcf9d2000838228d
😎 Deploy Preview https://deploy-preview-508--endearing-brigadeiros-63f9d0.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@LewisBroadhurst LewisBroadhurst marked this pull request as ready for review March 30, 2024 21:05
@JamieSlome JamieSlome self-assigned this Apr 4, 2024
@JamieSlome JamieSlome self-requested a review April 4, 2024 10:22
@JamieSlome
Copy link
Member

@LewisBroadhurst - thanks for the pull request - you're a star ⭐

In terms of keeping the old console.log calls, is there anything this would provide us that the usage of winston does not?

scripts/prepare.js Outdated Show resolved Hide resolved
scripts/prepare.js Outdated Show resolved Hide resolved
scripts/doc-schema.js Outdated Show resolved Hide resolved
scripts/doc-schema.js Outdated Show resolved Hide resolved
Copy link
Member

@JamieSlome JamieSlome left a comment

Choose a reason for hiding this comment

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

Looking good! 🍰

Can we think about whether we should use winston logging in log() in Step.js:

log(message) {
    const m = `${this.stepName} - ${message}`;
    this.logs.push(m);
    console.info(m);
}

Copy link

codecov bot commented Apr 5, 2024

Codecov Report

Attention: Patch coverage is 56.52174% with 20 lines in your changes are missing coverage. Please review.

Project coverage is 57.97%. Comparing base (e6eec8e) to head (c955e73).

❗ Current head c955e73 differs from pull request most recent head 520c5a5. Consider uploading reports for the commit 520c5a5 to get more accurate results

Files Patch % Lines
src/proxy/routes/index.js 14.28% 6 Missing ⚠️
src/config/index.js 25.00% 3 Missing ⚠️
packages/git-proxy-notify-hello/index.js 0.00% 2 Missing ⚠️
src/db/index.js 50.00% 2 Missing ⚠️
src/plugin.js 33.33% 2 Missing ⚠️
src/proxy/chain.js 33.33% 2 Missing ⚠️
src/proxy/processors/push-action/getDiff.js 0.00% 1 Missing ⚠️
src/service/routes/auth.js 66.66% 1 Missing ⚠️
src/service/routes/users.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #508      +/-   ##
==========================================
+ Coverage   56.96%   57.97%   +1.01%     
==========================================
  Files          46       40       -6     
  Lines        1566     1078     -488     
==========================================
- Hits          892      625     -267     
+ Misses        674      453     -221     

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

@LewisBroadhurst
Copy link
Author

Looking good! 🍰

Can we think about whether we should use winston logging in log() in Step.js:

log(message) {
    const m = `${this.stepName} - ${message}`;
    this.logs.push(m);
    console.info(m);
}

I think this is an example of keeping the console.log I mentioned initially, as having the values logged to console will be a much better UX? (and an npx installer wouldn't have log access?)

For this would the best solution be adding the winston logging in to the step, as well as keeping the console.log? Then we get the UX positives and logging.

Can remove the double logging from checkRepoInAuthorisedList.js with this too 😄

step.log(`repo ${action.repo} is not in the authorisedList, ending`);
- logger.info('setting error');

step.setError(`Rejecting repo ${action.repo} not in the authorisedList`);
- logger.error(`Rejecting repo ${action.repo} not in the authorisedList`);
+ log(message, isError = false) {
     const m = `${this.stepName} - ${message}`;
     this.logs.push(m);
+   if (!isError) {
+     console.info(m);
+     logger.info(m);
+   } else {
+     console.error(m);
+     logger.error(m);
+   }

Copy link
Contributor

@coopernetes coopernetes left a comment

Choose a reason for hiding this comment

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

Small suggestion on winston setup.

src/logging/index.js Outdated Show resolved Hide resolved
@coopernetes
Copy link
Contributor

@LewisBroadhurst are you able to address the conflicts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace console.log with structured logging
3 participants