added tests for the fileSync appender and changed the behavior of fileSync to create an empty log when called, just like the file appender does
This commit is contained in:
18
lib/appenders/fileSync.js
Normal file → Executable file
18
lib/appenders/fileSync.js
Normal file → Executable file
@@ -31,6 +31,7 @@ function RollingFileSync (filename, size, backups, options) {
|
||||
fileSize = fs.statSync(file).size;
|
||||
} catch (e) {
|
||||
// file does not exist
|
||||
fs.appendFileSync(filename, '');
|
||||
}
|
||||
return fileSize;
|
||||
}
|
||||
@@ -128,6 +129,7 @@ RollingFileSync.prototype.write = function(chunk, encoding) {
|
||||
* has been reached (default 5)
|
||||
*/
|
||||
function fileAppender (file, layout, logSize, numBackups) {
|
||||
debug("fileSync appender created");
|
||||
var bytesWritten = 0;
|
||||
file = path.normalize(file);
|
||||
layout = layout || layouts.basicLayout;
|
||||
@@ -145,11 +147,17 @@ function fileAppender (file, layout, logSize, numBackups) {
|
||||
numFiles
|
||||
);
|
||||
} else {
|
||||
stream = (function(f){
|
||||
return {write: function(data, encoding) {
|
||||
encoding = encoding || 'utf8';
|
||||
fs.appendFileSync(f, data, {encoding: encoding});
|
||||
}};
|
||||
stream = (function(f) {
|
||||
// create file if it doesn't exist
|
||||
if (!fs.existsSync(f))
|
||||
fs.appendFileSync(f, '');
|
||||
|
||||
return {
|
||||
write: function(data, encoding) {
|
||||
encoding = encoding || 'utf8';
|
||||
fs.appendFileSync(f, data, {encoding: encoding});
|
||||
}
|
||||
};
|
||||
})(file);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user