fixed a issue with the encoding on node 0.8

This commit is contained in:
Maycon Bordin
2013-12-12 22:26:48 -02:00
parent 60a84f16cf
commit 7fcdb2e651
2 changed files with 17 additions and 37 deletions

View File

@@ -102,7 +102,7 @@ RollingFileSync.prototype.write = function(chunk, encoding) {
function writeTheChunk() {
debug("writing the chunk to the file");
that.currentSize += chunk.length;
fs.appendFileSync(that.filename, chunk, {encoding: encoding});
fs.appendFileSync(that.filename, chunk);
}
debug("in write");
@@ -153,9 +153,8 @@ function fileAppender (file, layout, logSize, numBackups) {
fs.appendFileSync(f, '');
return {
write: function(data, encoding) {
encoding = encoding || 'utf8';
fs.appendFileSync(f, data, {encoding: encoding});
write: function(data) {
fs.appendFileSync(f, data);
}
};
})(file);
@@ -167,7 +166,7 @@ function fileAppender (file, layout, logSize, numBackups) {
var logFile = openTheStream(file, logSize, numBackups);
return function(loggingEvent) {
logFile.write(layout(loggingEvent) + eol, "utf8");
logFile.write(layout(loggingEvent) + eol);
};
}

View File

@@ -17,29 +17,10 @@ function remove(filename) {
}
vows.describe('log4js fileSyncAppender').addBatch({
'adding multiple fileAppenders': {
topic: function () {
var listenersCount = process.listeners('exit').length
, logger = log4js.getLogger('default-settings')
, count = 5, logfile;
while (count--) {
logfile = path.join(__dirname, '/fa-default-test' + count + '.log');
log4js.addAppender(require('../lib/appenders/fileSync').appender(logfile), 'default-settings');
}
return listenersCount;
},
'does not add more than one `exit` listeners': function (initialCount) {
assert.ok(process.listeners('exit').length <= initialCount + 1);
}
},
'with default fileAppender settings': {
'with default fileSyncAppender settings': {
topic: function() {
var that = this
, testFile = path.join(__dirname, '/fa-default-test.log')
, testFile = path.join(__dirname, '/fa-default-sync-test.log')
, logger = log4js.getLogger('default-settings');
remove(testFile);
@@ -62,7 +43,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
},
'with a max file size and no backups': {
topic: function() {
var testFile = path.join(__dirname, '/fa-maxFileSize-test.log')
var testFile = path.join(__dirname, '/fa-maxFileSize-sync-test.log')
, logger = log4js.getLogger('max-file-size')
, that = this;
remove(testFile);
@@ -90,7 +71,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
'starting with the test file name should be two': function(err, files) {
//there will always be one backup if you've specified a max log size
var logFiles = files.filter(
function(file) { return file.indexOf('fa-maxFileSize-test.log') > -1; }
function(file) { return file.indexOf('fa-maxFileSize-sync-test.log') > -1; }
);
assert.equal(logFiles.length, 2);
}
@@ -98,7 +79,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
},
'with a max file size and 2 backups': {
topic: function() {
var testFile = path.join(__dirname, '/fa-maxFileSize-with-backups-test.log')
var testFile = path.join(__dirname, '/fa-maxFileSize-with-backups-sync-test.log')
, logger = log4js.getLogger('max-file-size-backups');
remove(testFile);
remove(testFile+'.1');
@@ -127,7 +108,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
'the log files': {
topic: function(files) {
var logFiles = files.filter(
function(file) { return file.indexOf('fa-maxFileSize-with-backups-test.log') > -1; }
function(file) { return file.indexOf('fa-maxFileSize-with-backups-sync-test.log') > -1; }
);
return logFiles;
},
@@ -136,9 +117,9 @@ vows.describe('log4js fileSyncAppender').addBatch({
},
'should be named in sequence': function (files) {
assert.deepEqual(files, [
'fa-maxFileSize-with-backups-test.log',
'fa-maxFileSize-with-backups-test.log.1',
'fa-maxFileSize-with-backups-test.log.2'
'fa-maxFileSize-with-backups-sync-test.log',
'fa-maxFileSize-with-backups-sync-test.log.1',
'fa-maxFileSize-with-backups-sync-test.log.2'
]);
},
'and the contents of the first file': {
@@ -169,17 +150,17 @@ vows.describe('log4js fileSyncAppender').addBatch({
}
}).addBatch({
'configure' : {
'with fileAppender': {
'with fileSyncAppender': {
topic: function() {
var log4js = require('../lib/log4js')
, logger;
//this config defines one file appender (to ./tmp-tests.log)
//this config defines one file appender (to ./tmp-sync-tests.log)
//and sets the log level for "tests" to WARN
log4js.configure({
appenders: [{
category: "tests",
type: "file",
filename: "tmp-tests.log",
filename: "tmp-sync-tests.log",
layout: { type: "messagePassThrough" }
}],
@@ -189,7 +170,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
logger.info('this should not be written to the file');
logger.warn('this should be written to the file');
fs.readFile('tmp-tests.log', 'utf8', this.callback);
fs.readFile('tmp-sync-tests.log', 'utf8', this.callback);
},
'should load appender configuration from a json file': function(err, contents) {
assert.include(contents, 'this should be written to the file\n');