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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/index.ts
Expand Up @@ -38,7 +38,11 @@ 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 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 ...

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)}

const debugFn = shouldDebug ?
<T, U> (key: string, fn: (arg: T) => U) => {
let i = 0
Expand Down