Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Conversation

@feedmeapples
Copy link
Contributor

@feedmeapples feedmeapples commented Jul 19, 2021

What was changed

Adds timestamps to console log, warn and error
Logs and error sample:

[user0@user0 w]$ npm run dev

> [email protected] dev /home/user0/w
> NODE_ENV=development node server.js

establishing insecure connection...
ℹ 「hot」: webpack: Compiling...
[2021-07-19T18:27:01.044Z] temporal-web up and listening on port 8088
[2021-07-19T18:27:01.044Z] webpack is compiling...
...

ℹ 「wdm」: Compiled successfully.
ℹ 「hot」: WebSocket Client Connected
[2021-07-19T18:30:07.920Z]  Error: CUSTOM ERROR
    at TemporalClient.listNamespaces (/home/user0/w/server/temporal-client/temporal-client.js:79:9)
    at async Proxy.<anonymous> (/home/user0/w/server/temporal-client/with-error-converter.js:30:18)
    at async /home/user0/w/server/routes.js:19:14
    at async initialize (/home/user0/w/server/auth/index.js:11:5)
    at async session (/home/user0/w/node_modules/koa-session/index.js:41:7)
    at async bodyParser (/home/user0/w/node_modules/koa-bodyparser/index.js:95:5)
    at async /home/user0/w/server/index.js:45:9

Why?

Helps investigating logs

Checklist

  1. Closes

  2. How was this tested:

  1. Any docs updates needed?

return '[' + new Date().toISOString() + '] ';
};

const useConsoleTimestamp = () => {

Choose a reason for hiding this comment

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

Are you concerned that this is also likely going to override console.log (and its friends) for our dependencies as well since we're money patching a global?

Choose a reason for hiding this comment

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

I hate saying this out loud, but I almost wonder if we should use our own logging function rather than monkey-patching a Node global. We basically console.log about 7 times in the code base, so it's not a heavy lift.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes that's actually much safer. Will do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@feedmeapples feedmeapples requested a review from stevekinney July 20, 2021 19:01
server/logger.js Outdated
@@ -0,0 +1,20 @@
class Logger {

Choose a reason for hiding this comment

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

I might simplify it like this:

const timeStamp = () => '[' + new Date().toISOString() + ']';

const logger = {
  log: console.log.bind(null, timeStamp()),
  warn: console.warn.bind(null, timeStamp()),
  error: console.error.bind(null, timeStamp()),
  debug: console.debug.bind(null, timeStamp()),
}

module.exports = logger;

But, I don't think it really matters too much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+, implemented with .call though so timestamp value updates

@feedmeapples feedmeapples enabled auto-merge (squash) July 20, 2021 21:56
@feedmeapples feedmeapples merged commit 811ff6d into master Jul 20, 2021
@feedmeapples feedmeapples deleted the console-timestamp branch July 20, 2021 21:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants