Conversation
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.
Introduce `debug.unique([ format ])` method that returns function with
the same signature as `debug`. This function however prepends either
`'%d '` or `format + ' '` (depending on the presence of `format`) to the
first argument of original `debug` function, and supplies unique
integer as a second argument, shifting the rest to the right.
Example:
```
const debug = require('debug')('ns');
class Instance {
constructor() {
this.debug = debug.unique('id=%d ');
}
method() {
this.debug('method data=%j', {});
// "id=123 method data={}"
}
attach(other) {
this.debug('attach to=%d', other.debug.id());
// "id=123 attach to=456"
}
}
```
|
I probably prefer this one over #543. Perhaps, it might be worth adding colors to it eventually. |
1 similar comment
|
The coverage is down, because there are no tests 🤖 |
|
I definitely see the benefit of this one over #543, though I think the term |
|
I'm fine with naming it differently. |
|
I see the point now, @indutny - not sure why I wasn't getting it the last time I looked at this. Question is, why not just use another namespace? Also, sorry for taking so long to get back to this. |
|
Going to go ahead and close these two (this and #543) in lieu of #544 (comment) in order to clean up a bit - feel absolutely free to comment back here and we can pick up the discussion :) |
|
@qix |
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.
Introduce
debug.unique([ format ])method that returns function withthe same signature as
debug. This function however prepends either'%d 'orformat + ' '(depending on the presence offormat) to thefirst argument of original
debugfunction, and supplies uniqueinteger as a second argument, shifting the rest to the right.
Example:
Alternative to #543