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

Add timestamp to debug logging #994

Merged
merged 4 commits into from
Apr 7, 2020
Merged

Conversation

sylc
Copy link
Contributor

@sylc sylc commented Apr 2, 2020

This PR add timestamp for debug logging.

example output is

[ts-node 2020-04-02T12:35:37.097Z] directoryExists c/ts-node/node_modules/events 13

Associated with #754 (comment)

Copy link
Collaborator

@cspotcode cspotcode left a comment

Choose a reason for hiding this comment

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

Thanks! Left a couple comments because the implementation looks unnecessarily clever, but I like the idea.

src/index.ts Outdated
const timestamp = function(){};
timestamp.toString = function(){
return "[ts-node " + (new Date).toISOString() + "]";
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks unnecessarily clever. Let's keep it simple and call the function every time we need a timestamp. function timestamp() {return "ts-node ...

src/index.ts Outdated
timestamp.toString = function(){
return "[ts-node " + (new Date).toISOString() + "]";
}
const debug = shouldDebug ? console.log.bind(console, '%s', timestamp) : () => undefined
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO we should simplifying by writing a function.

function(...args) {console.log(timestamp(), ...args)}

@sylc
Copy link
Contributor Author

sylc commented Apr 3, 2020

I now actioned your comments.

src/index.ts Outdated
@@ -38,7 +38,9 @@ function yn (value: string | undefined) {
* Debugging `ts-node`.
*/
const shouldDebug = yn(process.env.TS_NODE_DEBUG)
const debug = shouldDebug ? console.log.bind(console, 'ts-node') : () => undefined
const debug = shouldDebug ?
(...args: any) => console.log(`ts-node ${new Date().toISOString()}`, ...args)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Square brackets need to be re-added. Otherwise looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done :)

Copy link
Collaborator

@cspotcode cspotcode left a comment

Choose a reason for hiding this comment

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

Thanks!

@cspotcode cspotcode merged commit 6e56c87 into TypeStrong:master Apr 7, 2020
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.

2 participants