@@ -116,6 +116,60 @@ describe('Test child logger', function () {
116116 } ) ;
117117 } ) ;
118118
119+ describe ( 'Test context features' , function ( ) {
120+
121+ describe ( 'Create child logger without context' , function ( ) {
122+
123+ beforeEach ( function ( ) {
124+ childLogger = log . createLogger ( ) ;
125+ } ) ;
126+
127+ it ( 'cannot set context properties' , function ( ) {
128+ expect ( childLogger . setContextProperty ( 'some-field' , 'some-value' ) ) . to . be . false ;
129+ } ) ;
130+
131+ it ( 'does not log a custom context property' , function ( ) {
132+ childLogger . setContextProperty ( 'some-field' , 'some-value' ) ;
133+ childLogger . warn ( 'test-message' ) ;
134+ expect ( lastOutput ) . to . not . include . key ( 'some-field' ) ;
135+ } ) ;
136+
137+ it ( 'does not log the correlation_id' , function ( ) {
138+ childLogger . warn ( "test-message" ) ;
139+ expect ( lastOutput ) . to . not . include . key ( 'correlation_id' ) ;
140+ } ) ;
141+ } ) ;
142+
143+ describe ( 'Create child logger with new context' , function ( ) {
144+
145+ beforeEach ( function ( ) {
146+ childLogger = log . createLogger ( null , true ) ;
147+ } ) ;
148+
149+ it ( 'sets context properties' , function ( ) {
150+ expect ( childLogger . setContextProperty ( 'some-field' , 'some-value' ) ) . to . be . true ;
151+ } ) ;
152+
153+ it ( 'logs a custom context property' , function ( ) {
154+ childLogger . setContextProperty ( 'some-field' , 'some-value' ) ;
155+ childLogger . warn ( 'test-message' ) ;
156+ expect ( lastOutput ) . to . include . property ( 'some-field' , 'some-value' ) ;
157+ } ) ;
158+
159+ it ( 'inherits the context' , function ( ) {
160+ childLogger . setContextProperty ( 'some-field' , 'some-value' ) ;
161+ childLogger . createLogger ( ) . warn ( 'test-message' ) ;
162+ expect ( lastOutput ) . to . include . property ( 'some-field' , 'some-value' ) ;
163+ } ) ;
164+
165+ it ( 'generates a correlation_id' , function ( ) {
166+ childLogger . warn ( "test-message" ) ;
167+ expect ( lastOutput ) . to . include . key ( 'correlation_id' ) ;
168+ expect ( lastOutput . correlation_id ) . to . match ( / [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - 4 [ 0 - 9 a - f ] { 3 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } / ) ;
169+ } ) ;
170+ } ) ;
171+ } ) ;
172+
119173 describe ( 'Set logging level threshold per child logger' , function ( ) {
120174
121175 describe ( 'Child logger sets treshold' , function ( ) {
0 commit comments