fixed a issue with the encoding on node 0.8
This commit is contained in:
@@ -102,7 +102,7 @@ RollingFileSync.prototype.write = function(chunk, encoding) {
|
|||||||
function writeTheChunk() {
|
function writeTheChunk() {
|
||||||
debug("writing the chunk to the file");
|
debug("writing the chunk to the file");
|
||||||
that.currentSize += chunk.length;
|
that.currentSize += chunk.length;
|
||||||
fs.appendFileSync(that.filename, chunk, {encoding: encoding});
|
fs.appendFileSync(that.filename, chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("in write");
|
debug("in write");
|
||||||
@@ -153,9 +153,8 @@ function fileAppender (file, layout, logSize, numBackups) {
|
|||||||
fs.appendFileSync(f, '');
|
fs.appendFileSync(f, '');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
write: function(data, encoding) {
|
write: function(data) {
|
||||||
encoding = encoding || 'utf8';
|
fs.appendFileSync(f, data);
|
||||||
fs.appendFileSync(f, data, {encoding: encoding});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})(file);
|
})(file);
|
||||||
@@ -167,7 +166,7 @@ function fileAppender (file, layout, logSize, numBackups) {
|
|||||||
var logFile = openTheStream(file, logSize, numBackups);
|
var logFile = openTheStream(file, logSize, numBackups);
|
||||||
|
|
||||||
return function(loggingEvent) {
|
return function(loggingEvent) {
|
||||||
logFile.write(layout(loggingEvent) + eol, "utf8");
|
logFile.write(layout(loggingEvent) + eol);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,29 +17,10 @@ function remove(filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vows.describe('log4js fileSyncAppender').addBatch({
|
vows.describe('log4js fileSyncAppender').addBatch({
|
||||||
'adding multiple fileAppenders': {
|
'with default fileSyncAppender settings': {
|
||||||
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': {
|
|
||||||
topic: function() {
|
topic: function() {
|
||||||
var that = this
|
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');
|
, logger = log4js.getLogger('default-settings');
|
||||||
remove(testFile);
|
remove(testFile);
|
||||||
|
|
||||||
@@ -62,7 +43,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
|
|||||||
},
|
},
|
||||||
'with a max file size and no backups': {
|
'with a max file size and no backups': {
|
||||||
topic: function() {
|
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')
|
, logger = log4js.getLogger('max-file-size')
|
||||||
, that = this;
|
, that = this;
|
||||||
remove(testFile);
|
remove(testFile);
|
||||||
@@ -90,7 +71,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
|
|||||||
'starting with the test file name should be two': function(err, files) {
|
'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
|
//there will always be one backup if you've specified a max log size
|
||||||
var logFiles = files.filter(
|
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);
|
assert.equal(logFiles.length, 2);
|
||||||
}
|
}
|
||||||
@@ -98,7 +79,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
|
|||||||
},
|
},
|
||||||
'with a max file size and 2 backups': {
|
'with a max file size and 2 backups': {
|
||||||
topic: function() {
|
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');
|
, logger = log4js.getLogger('max-file-size-backups');
|
||||||
remove(testFile);
|
remove(testFile);
|
||||||
remove(testFile+'.1');
|
remove(testFile+'.1');
|
||||||
@@ -127,7 +108,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
|
|||||||
'the log files': {
|
'the log files': {
|
||||||
topic: function(files) {
|
topic: function(files) {
|
||||||
var logFiles = files.filter(
|
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;
|
return logFiles;
|
||||||
},
|
},
|
||||||
@@ -136,9 +117,9 @@ vows.describe('log4js fileSyncAppender').addBatch({
|
|||||||
},
|
},
|
||||||
'should be named in sequence': function (files) {
|
'should be named in sequence': function (files) {
|
||||||
assert.deepEqual(files, [
|
assert.deepEqual(files, [
|
||||||
'fa-maxFileSize-with-backups-test.log',
|
'fa-maxFileSize-with-backups-sync-test.log',
|
||||||
'fa-maxFileSize-with-backups-test.log.1',
|
'fa-maxFileSize-with-backups-sync-test.log.1',
|
||||||
'fa-maxFileSize-with-backups-test.log.2'
|
'fa-maxFileSize-with-backups-sync-test.log.2'
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
'and the contents of the first file': {
|
'and the contents of the first file': {
|
||||||
@@ -169,17 +150,17 @@ vows.describe('log4js fileSyncAppender').addBatch({
|
|||||||
}
|
}
|
||||||
}).addBatch({
|
}).addBatch({
|
||||||
'configure' : {
|
'configure' : {
|
||||||
'with fileAppender': {
|
'with fileSyncAppender': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
var log4js = require('../lib/log4js')
|
var log4js = require('../lib/log4js')
|
||||||
, logger;
|
, 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
|
//and sets the log level for "tests" to WARN
|
||||||
log4js.configure({
|
log4js.configure({
|
||||||
appenders: [{
|
appenders: [{
|
||||||
category: "tests",
|
category: "tests",
|
||||||
type: "file",
|
type: "file",
|
||||||
filename: "tmp-tests.log",
|
filename: "tmp-sync-tests.log",
|
||||||
layout: { type: "messagePassThrough" }
|
layout: { type: "messagePassThrough" }
|
||||||
}],
|
}],
|
||||||
|
|
||||||
@@ -189,7 +170,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
|
|||||||
logger.info('this should not be written to the file');
|
logger.info('this should not be written to the file');
|
||||||
logger.warn('this should 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) {
|
'should load appender configuration from a json file': function(err, contents) {
|
||||||
assert.include(contents, 'this should be written to the file\n');
|
assert.include(contents, 'this should be written to the file\n');
|
||||||
|
|||||||
Reference in New Issue
Block a user