-
Notifications
You must be signed in to change notification settings - Fork 49
Add timestamp to console log #363
Conversation
68f289f to
0abbaab
Compare
server/use-console-timestamp.js
Outdated
| return '[' + new Date().toISOString() + '] '; | ||
| }; | ||
|
|
||
| const useConsoleTimestamp = () => { |
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.
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?
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 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.
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.
yes that's actually much safer. Will do
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.
updated
0abbaab to
7dcc72a
Compare
server/logger.js
Outdated
| @@ -0,0 +1,20 @@ | |||
| class Logger { | |||
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 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.
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.
+, implemented with .call though so timestamp value updates
What was changed
Adds timestamps to console
log,warnanderrorLogs and error sample:
Why?
Helps investigating logs
Checklist
Closes
How was this tested: