@@ -333,6 +333,46 @@ test("log4js fileAppender", batch => {
333
333
} ) ;
334
334
t . end ( ) ;
335
335
} ) ;
336
+
337
+ batch . test ( "with removeColor fileAppender settings" , async t => {
338
+ const testFilePlain = path . join ( __dirname , "fa-removeColor-test.log" ) ;
339
+ const testFileAsIs = path . join ( __dirname , "fa-asIs-test.log" ) ;
340
+ const logger = log4js . getLogger ( "default-settings" ) ;
341
+ await removeFile ( testFilePlain ) ;
342
+ await removeFile ( testFileAsIs ) ;
343
+
344
+ t . tearDown ( async ( ) => {
345
+ await new Promise ( resolve => log4js . shutdown ( resolve ) ) ;
346
+ await removeFile ( testFilePlain ) ;
347
+ await removeFile ( testFileAsIs ) ;
348
+ } ) ;
349
+
350
+ log4js . configure ( {
351
+ appenders : {
352
+ plainFile : { type : "file" , filename : testFilePlain , removeColor : true } ,
353
+ asIsFile : { type : "file" , filename : testFilePlain , removeColor : false }
354
+ } ,
355
+ categories : { default : { appenders : [ "plainFile" , "asIsFile" ] , level : "debug" } }
356
+ } ) ;
357
+
358
+ logger . info ( "This should be in the file. \x1b[33mColor\x1b[0m \x1b[93;41mshould\x1b[0m be \x1b[38;5;8mplain\x1b[0m." ) ;
359
+
360
+ await sleep ( 100 ) ;
361
+ let fileContents = await fs . readFile ( testFilePlain , "utf8" ) ;
362
+ t . include ( fileContents , `This should be in the file. Color should be plain.${ EOL } ` ) ;
363
+ t . match (
364
+ fileContents ,
365
+ / \[ \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } \. \d { 3 } ] \[ I N F O ] d e f a u l t - s e t t i n g s - /
366
+ ) ;
367
+
368
+ fileContents = await fs . readFile ( testFileAsIs , "utf8" ) ;
369
+ t . include ( fileContents , `This should be in the file. \x1b[33mColor\x1b[0m \x1b[93;41mshould\x1b[0m be \x1b[38;5;8mplain\x1b[0m.${ EOL } ` ) ;
370
+ t . match (
371
+ fileContents ,
372
+ / \[ \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } \. \d { 3 } ] \[ I N F O ] d e f a u l t - s e t t i n g s - /
373
+ ) ;
374
+ t . end ( ) ;
375
+ } ) ;
336
376
337
377
batch . end ( ) ;
338
378
} ) ;
0 commit comments