File tree Expand file tree Collapse file tree 3 files changed +33
-7
lines changed Expand file tree Collapse file tree 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]
104104where ` 3245 ` is the process id. If it is not run with that
105105environment variable set, then it will not print anything.
106106
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+
107120Multiple comma-separated ` section ` names may be specified in the ` NODE_DEBUG `
108121environment variable. For example: ` NODE_DEBUG=fs,net,tls ` .
109122
Original file line number Diff line number Diff line change @@ -230,17 +230,21 @@ function format(f) {
230230 return str ;
231231}
232232
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+ }
235243
236244function debuglog ( set ) {
237- if ( debugEnviron === undefined ) {
238- debugEnviron = new Set (
239- ( process . env . NODE_DEBUG || '' ) . split ( ',' ) . map ( ( s ) => s . toUpperCase ( ) ) ) ;
240- }
241245 set = set . toUpperCase ( ) ;
242246 if ( ! debugs [ set ] ) {
243- if ( debugEnviron . has ( set ) ) {
247+ if ( debugEnvRegex . test ( set ) ) {
244248 var pid = process . pid ;
245249 debugs [ set ] = function ( ) {
246250 var msg = exports . format . apply ( exports , arguments ) ;
Original file line number Diff line number Diff line change @@ -43,6 +43,15 @@ function parent() {
4343 test ( 'f$oo' , true , 'f$oo' ) ;
4444 test ( 'f$oo' , false , 'f.oo' ) ;
4545 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' ) ;
4655}
4756
4857function test ( environ , shouldWrite , section ) {
You can’t perform that action at this time.
0 commit comments