Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dateFile error handling fix #1097

Merged
merged 2 commits into from Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/appenders/dateFile.js
Expand Up @@ -22,17 +22,26 @@ function appender(
// options should work for dateFile as well.
options.maxSize = options.maxLogSize;

let alive = true;

const logFile = new streams.DateRollingFileStream(
filename,
pattern,
options
);

logFile.on('error', (err) => {
lamweili marked this conversation as resolved.
Show resolved Hide resolved
alive = false;
console.error('log4js.dateFileAppender - Writing to file %s, error happened ', filename, err); //eslint-disable-line
});
logFile.on("drain", () => {
process.emit("log4js:pause", false);
});

const app = function (logEvent) {
if (!alive) {
return;
}
if (!logFile.write(layout(logEvent, timezoneOffset) + eol, "utf8")) {
process.emit("log4js:pause", true);
}
Expand Down
12 changes: 9 additions & 3 deletions lib/appenders/file.js
Expand Up @@ -12,9 +12,6 @@ function openTheStream(file, fileSize, numFiles, options) {
numFiles,
options
);
stream.on('error', (err) => {
console.error('log4js.fileAppender - Writing to file %s, error happened ', file, err); //eslint-disable-line
});
stream.on('drain', () => {
process.emit("log4js:pause", false);
});
Expand Down Expand Up @@ -50,9 +47,18 @@ function fileAppender(file, layout, logSize, numBackups, options, timezoneOffset
timezoneOffset, ')'
);

let alive = true;

let writer = openTheStream(file, logSize, numBackups, options);
writer.on('error', (err) => {
alive = false;
console.error('log4js.fileAppender - Writing to file %s, error happened ', file, err); //eslint-disable-line
});

const app = function (loggingEvent) {
if (!alive) {
return;
}
if (options.removeColor === true) {
// eslint-disable-next-line no-control-regex
const regex = /\x1b[[0-9;]*m/g;
Expand Down