File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ module.exports = function setup(env) {
123123 debug . useColors = createDebug . useColors ( ) ;
124124 debug . color = selectColor ( namespace ) ;
125125 debug . destroy = destroy ;
126+ debug . extend = extend ;
126127 //debug.formatArgs = formatArgs;
127128 //debug.rawLog = rawLog;
128129
@@ -146,6 +147,14 @@ module.exports = function setup(env) {
146147 }
147148 }
148149
150+ function extend ( namespace , delimiter ) {
151+ if ( typeof delimiter === 'undefined' ) {
152+ delimiter = ':' ;
153+ }
154+
155+ return createDebug ( this . namespace + delimiter + namespace ) ;
156+ }
157+
149158 /**
150159 * Enables a debug mode by namespaces. This can include modes
151160 * separated by a colon and wildcards.
Original file line number Diff line number Diff line change @@ -64,4 +64,30 @@ describe('debug', function () {
6464 } ) ;
6565 } ) ;
6666
67+
68+ describe ( 'extend namespace' , function ( ) {
69+ var log ;
70+
71+ beforeEach ( function ( ) {
72+ debug . enable ( 'foo' ) ;
73+ log = debug ( 'foo' ) ;
74+ } ) ;
75+
76+ it ( 'should extend namespace' , function ( ) {
77+ var logBar = log . extend ( 'bar' ) ;
78+ expect ( logBar . namespace ) . to . be . equal ( 'foo:bar' ) ;
79+ } ) ;
80+
81+ it ( 'should extend namespace with custom delimiter' , function ( ) {
82+ var logBar = log . extend ( 'bar' , '--' ) ;
83+ expect ( logBar . namespace ) . to . be . equal ( 'foo--bar' ) ;
84+ } ) ;
85+
86+ it ( 'should extend namespace with empty delimiter' , function ( ) {
87+ var logBar = log . extend ( 'bar' , '' ) ;
88+ expect ( logBar . namespace ) . to . be . equal ( 'foobar' ) ;
89+ } ) ;
90+
91+ } ) ;
92+
6793} ) ;
You can’t perform that action at this time.
0 commit comments