8000 Using regexp literal and `.map` instead of a loop for replacing · helloyou2012/log4js-node@40b5f09 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 40b5f09

Browse files
committed
Using regexp literal and .map instead of a loop for replacing
Signed-off-by: Cocoa <0xbbc@0xbbc.com>
1 parent b088498 commit 40b5f09

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

lib/appenders/file.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,8 @@ function fileAppender(file, layout, logSize, numBackups, options, timezoneOffset
5555
const app = function (loggingEvent) {
5656
if (options.removeColor === true) {
5757
// eslint-disable-next-line no-control-regex
58-
const regex = new RegExp("\x1b[[0-9;]*m", "g");
59-
for (let i = 0; i < loggingEvent.data.length; i += 1) {
60-
let d = loggingEvent.data[i];
61-
d = d.replace(regex, '');
62-
loggingEvent.data[i] = d;
63-
}
58+
const regex = /\x1b[[0-9;]*m/g;
59+
loggingEvent.data = loggingEvent.data.map(d => d.replace(regex, ''))
6460
}
6561
if (!writer.write(layout(loggingEvent, timezoneOffset) + eol, "utf8")) {
6662
process.emit('log4js:pause', true);

0 commit comments

Comments
 (0)
0