Commit 6d9b1e4 1 parent ec443c3 commit 6d9b1e4 Copy full SHA for 6d9b1e4
File tree 3 files changed +33
-7
lines changed
3 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,19 @@ FOO 3245: hello from foo [123]
104
104
where ` 3245 ` is the process id. If it is not run with that
105
105
environment variable set, then it will not print anything.
106
106
107
+ The ` section ` supports wildcard also, for example:
108
+ ``` js
109
+ const util = require (' util' );
110
+ const debuglog = util .debuglog (' foo-bar' );
111
+
112
+ debuglog (' hi there, it\' s foo-bar [%d]' , 2333 );
113
+ ```
114
+
115
+ if it is run with ` NODE_DEBUG=foo* ` in the environment, then it will output something like:
116
+ ``` txt
117
+ FOO-BAR 3257: hi there, it's foo-bar [2333]
118
+ ```
119
+
107
120
Multiple comma-separated ` section ` names may be specified in the ` NODE_DEBUG `
108
121
environment variable. For example: ` NODE_DEBUG=fs,net,tls ` .
109
122
Original file line number Diff line number Diff line change @@ -230,17 +230,21 @@ function format(f) {
230
230
return str ;
231
231
}
232
232
233
- var debugs = { } ;
234
- var debugEnviron ;
233
+ const debugs = { } ;
234
+ let debugEnvRegex = / ^ $ / ;
235
+ if ( process . env . NODE_DEBUG ) {
236
+ let debugEnv = process . env . NODE_DEBUG ;
237
+ debugEnv = debugEnv . replace ( / [ | \\ { } ( ) [ \] ^ $ + ? . ] / g, '\\$&' )
238
+ . replace ( / \* / g, '.*' )
239
+ . replace ( / , / g, '$|^' )
240
+ . toUpperCase ( ) ;
241
+ debugEnvRegex = new RegExp ( `^${ debugEnv } $` , 'i' ) ;
242
+ }
235
243
236
244
function debuglog ( set ) {
237
- if ( debugEnviron === undefined ) {
238
- debugEnviron = new Set (
239
- ( process . env . NODE_DEBUG || '' ) . split ( ',' ) . map ( ( s ) => s . toUpperCase ( ) ) ) ;
240
- }
241
245
set = set . toUpperCase ( ) ;
242
246
if ( ! debugs [ set ] ) {
243
- if ( debugEnviron . has ( set ) ) {
247
+ if ( debugEnvRegex . test ( set ) ) {
244
248
var pid = process . pid ;
245
249
debugs [ set ] = function ( ) {
246
250
var msg = exports . format . apply ( exports , arguments ) ;
Original file line number Diff line number Diff line change @@ -43,6 +43,15 @@ function parent() {
43
43
test ( 'f$oo' , true , 'f$oo' ) ;
44
44
test ( 'f$oo' , false , 'f.oo' ) ;
45
45
test ( 'no-bar-at-all' , false , 'bar' ) ;
46
+
47
+ test ( 'test-abc' , true , 'test-abc' ) ;
48
+ test ( 'test-a' , false , 'test-abc' ) ;
49
+ test ( 'test-*' , true , 'test-abc' ) ;
50
+ test ( 'test-*c' , true , 'test-abc' ) ;
51
+ test ( 'test-*abc' , true , 'test-abc' ) ;
52
+ test ( 'abc-test' , true , 'abc-test' ) ;
53
+ test ( 'a*-test' , true , 'abc-test' ) ;
54
+ test ( '*-test' , true , 'abc-test' ) ;
46
55
}
47
56
48
57
function test ( environ , shouldWrite , section ) {
You can’t perform that action at this time.
0 commit comments