Skip to content

Commit

Permalink
Using regexp literal and .map instead of a loop for replacing
Browse files Browse the repository at this point in the history
Signed-off-by: Cocoa <0xbbc@0xbbc.com>
  • Loading branch information
BlueCocoa committed May 7, 2020
1 parent b088498 commit 40b5f09
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/appenders/file.js
Expand Up @@ -55,12 +55,8 @@ function fileAppender(file, layout, logSize, numBackups, options, timezoneOffset
const app = function (loggingEvent) {
if (options.removeColor === true) {
// eslint-disable-next-line no-control-regex
const regex = new RegExp("\x1b[[0-9;]*m", "g");
for (let i = 0; i < loggingEvent.data.length; i += 1) {
let d = loggingEvent.data[i];
d = d.replace(regex, '');
loggingEvent.data[i] = d;
}
const regex = /\x1b[[0-9;]*m/g;
loggingEvent.data = loggingEvent.data.map(d => d.replace(regex, ''))
}
if (!writer.write(layout(loggingEvent, timezoneOffset) + eol, "utf8")) {
process.emit('log4js:pause', true);
Expand Down

0 comments on commit 40b5f09

Please sign in to comment.