-
Notifications
You must be signed in to change notification settings - Fork 22
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
added timestamps to the API consumption logs #3732
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,5 @@ | ||||||||||||||||||||
const moment = require("moment"); | ||||||||||||||||||||
|
||||||||||||||||||||
const logText = (message) => { | ||||||||||||||||||||
if (process.env.NODE_ENV !== "production") { | ||||||||||||||||||||
console.log(message); | ||||||||||||||||||||
|
@@ -28,4 +30,14 @@ const logError = (error) => { | |||||||||||||||||||
return "log deactivated in prod and stage"; | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
module.exports = { logText, logElement, logObject, logError }; | ||||||||||||||||||||
const logTextWithTimestamp = (message) => { | ||||||||||||||||||||
console.log(`[${moment().format("YYYY-MM-DD HH:mm:ss")}] ${message}`); | ||||||||||||||||||||
}; | ||||||||||||||||||||
Comment on lines
+33
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align logTextWithTimestamp with existing logging patterns The new function differs from other logging utilities in three ways:
Suggested implementation: const logTextWithTimestamp = (message) => {
- console.log(`[${moment().format("YYYY-MM-DD HH:mm:ss")}] ${message}`);
+ if (process.env.NODE_ENV !== "production") {
+ console.log(`[${moment().format("YYYY-MM-DD HH:mm:ss")}] ${message}`);
+ }
+ return "log deactivated in prod and stage";
}; 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
module.exports = { | ||||||||||||||||||||
logText, | ||||||||||||||||||||
logTextWithTimestamp, | ||||||||||||||||||||
logElement, | ||||||||||||||||||||
logObject, | ||||||||||||||||||||
logError, | ||||||||||||||||||||
}; |
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.
🛠️ Refactor suggestion
Consider using native Date methods instead of moment.js
For simple timestamp formatting, native JavaScript methods like
new Date().toISOString()
orIntl.DateTimeFormat
could be more performant alternatives to moment.js, which is a relatively heavy library.Example implementation: