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:
Maycon Bordin
2013-12-12 18:16:53 -02:00
parent 723dbec964
commit 60a84f16cf
2 changed files with 213 additions and 5 deletions

18
lib/appenders/fileSync.js Normal file → Executable file
View 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);
}