Added support for removing embedded ANSI color sequence for file appender#1001
Added support for removing embedded ANSI color sequence for file appender#1001nomiddlename merged 10 commits intolog4js-node:masterfrom BlueCocoa:master
Conversation
Signed-off-by: Cocoa <[email protected]>
|
@BlueCocoa I am not a maintainer, but thank for the idea! Can you fix those ESLint errors? There is a couple of other cases to consider, like three-digits color codes and codes separated by a semicolon (see https://en.wikipedia.org/wiki/ANSI_escape_code and https://superuser.com/questions/380772/removing-ansi-color-codes-from-text-stream) |
Signed-off-by: Cocoa <[email protected]>
Hi @rnd-debug, thanks for your kindly reply and the hint on ANSI color codes. I've made corresponding changes in the second commit. I think that should fix all the issues that ESLint complained. |
|
According to the ESLint docs, perhaps we should turn off |
Signed-off-by: Cocoa <[email protected]>
Signed-off-by: Cocoa <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #1001 +/- ##
==========================================
- Coverage 98.64% 98.55% -0.10%
==========================================
Files 25 25
Lines 1030 1035 +5
==========================================
+ Hits 1016 1020 +4
- Misses 14 15 +1
Continue to review full report at Codecov.
|
Signed-off-by: Cocoa <[email protected]>
…um line length Signed-off-by: Cocoa <[email protected]>
Signed-off-by: Cocoa <[email protected]>
nomiddlename
left a comment
There was a problem hiding this comment.
Thanks for doing this, much appreciated. (Also thanks to @rnd-debug for their suggestions as well). I've made a couple of comments, see if you think they make sense.
Signed-off-by: Cocoa <[email protected]>
|
Hi @nomiddlename, much thanks to your suggestions, corresponding changes has been made and pushed :-D |
|
Sorry @BlueCocoa - I just thought of a problem with this. The const thing = { a: 'value' };
logger.debug('this is the thing: ', thing);I think your code will throw an error in this case. |
Signed-off-by: Cocoa <[email protected]>
Signed-off-by: Cocoa <[email protected]>
|
Fix published in [email protected] |

It's quite common for developers to use embedded color sequence like
\x1b[33min the log string to make the output look beautiful.However, if the output is also set to append to some file, the embedded color sequence will write to the given file as is, which may not be expected in some cases.
Thus I added one more option for file appender, which is
removeColor. It's a boolean value that controls whether if the appender should detect and remove embedded color sequence before writing to file.When this option is set to
false, everything will be written to file as is. For example,In the
app.log, it will be[33mHello[0m,\x1bis invisible.When this option is set to
true, then embedded color sequence will be removed before writing to file.Now in the
app.log, it will beHelloonly.Signed-off-by: Cocoa [email protected]