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

introduce debug.id helper method #543

Closed
wants to merge 1 commit into from

Conversation

indutny
Copy link

@indutny indutny commented Jan 23, 2018

When debugging the applications that work with pools of streams
or sockets, the debug stream often comes out interleaved making it
impossible to distinguish between streams. It is a common knowledge
that unique ids could be assigned to each stream and be used in
logging to solve this. However, this solution is rather ad-hoc and
usually applied only during manual debugging.

This commit introduces standard function debug.id() that
increments the internal counter only when debugging is enabled, and
otherwise returns undefined.


This have bugged me any times, but realization that it could be done in one place and for all came just now.

As a more questionable alternative, I think it could work differently too:

const debug = debug('app');

class Instance {
  constructor() {
    this.debug = debug.id('id=%d msg: %s');
  }

  method() {
    this.debug('message params=%j', {});
    // "app id=123 msg: message params={}"
  }

  workWithAnotherInstance(other) {
    this.debug('work with=%d', other.debug.id);
    // "app id=123 msg: work with=456"
  }
}

What do you think?

When debugging the applications that work with pools of streams
or sockets, the debug stream often comes out interleaved making it
impossible to distinguish between streams. It is a common knowledge
that unique `id`s could be assigned to each stream and be used in
logging to solve this. However, this solution is rather ad-hoc and
usually applied only during manual debugging.

This commit introduces standard function `debug.id()` that
increments the internal counter only when debugging is enabled, and
otherwise returns `undefined`.
@indutny
Copy link
Author

indutny commented Jan 23, 2018

Going to open a second PR for alternative.

@indutny indutny mentioned this pull request Jan 23, 2018
@coveralls
Copy link

Coverage Status

Coverage increased (+2.6%) to 76.331% when pulling 1141cf5 on indutny:feature/debug-id into 22f9932 on visionmedia:master.

1 similar comment
@coveralls
Copy link

coveralls commented Jan 23, 2018

Coverage Status

Coverage increased (+2.6%) to 76.331% when pulling 1141cf5 on indutny:feature/debug-id into 22f9932 on visionmedia:master.

@Qix-
Copy link
Member

Qix- commented Jun 20, 2018

Hello @indutny :)

What does the ID function solve? I mean, what would consume it?

@Qix- Qix- added feature This proposes or provides a feature or enhancement change-minor This proposes or provides a change that requires a minor release awaiting-response This issue or pull request is awaiting a user's response labels Jun 20, 2018
@Qix- Qix- closed this Dec 19, 2018
@Qix-
Copy link
Member

Qix- commented Dec 19, 2018

#544 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-response This issue or pull request is awaiting a user's response change-minor This proposes or provides a change that requires a minor release feature This proposes or provides a feature or enhancement
Development

Successfully merging this pull request may close these issues.

3 participants