converted date file appender tests to mocha
This commit is contained in:
@@ -136,7 +136,9 @@ function dispatch(event) {
|
|||||||
|
|
||||||
function load(file) {
|
function load(file) {
|
||||||
debug("loading ", file);
|
debug("loading ", file);
|
||||||
return JSON.parse(fs.readFileSync(file, "utf-8"));
|
var contents = fs.readFileSync(file, "utf-8");
|
||||||
|
debug("file contents ", contents);
|
||||||
|
return JSON.parse(contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
function configure(configurationFileOrObject) {
|
function configure(configurationFileOrObject) {
|
||||||
|
|||||||
@@ -1,153 +1,173 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var vows = require('vows')
|
var should = require('should')
|
||||||
, assert = require('assert')
|
, async = require('async')
|
||||||
, path = require('path')
|
, path = require('path')
|
||||||
, fs = require('fs')
|
, fs = require('fs')
|
||||||
, sandbox = require('sandboxed-module')
|
, sandbox = require('sandboxed-module');
|
||||||
, log4js = require('../lib/log4js');
|
|
||||||
|
|
||||||
function removeFile(filename) {
|
function remove(filename, cb) {
|
||||||
return function() {
|
fs.unlink(path.join(__dirname, filename), function(err) {
|
||||||
fs.unlink(path.join(__dirname, filename), function(err) {
|
cb();
|
||||||
if (err) {
|
});
|
||||||
console.log("Could not delete ", filename, err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vows.describe('../lib/appenders/dateFile').addBatch({
|
describe('../lib/appenders/dateFile', function() {
|
||||||
'appender': {
|
describe('adding multiple dateFileAppenders', function() {
|
||||||
'adding multiple dateFileAppenders': {
|
var files = [], initialListeners;
|
||||||
topic: function () {
|
|
||||||
var listenersCount = process.listeners('exit').length,
|
before(function() {
|
||||||
dateFileAppender = require('../lib/appenders/dateFile'),
|
var dateFileAppender = require('../lib/appenders/dateFile'),
|
||||||
count = 5,
|
count = 5,
|
||||||
logfile;
|
logfile;
|
||||||
|
|
||||||
while (count--) {
|
initialListeners = process.listeners('exit').length;
|
||||||
logfile = path.join(__dirname, 'datefa-default-test' + count + '.log');
|
|
||||||
log4js.addAppender(dateFileAppender.appender(logfile));
|
|
||||||
}
|
|
||||||
|
|
||||||
return listenersCount;
|
|
||||||
},
|
|
||||||
teardown: function() {
|
|
||||||
removeFile('datefa-default-test0.log')();
|
|
||||||
removeFile('datefa-default-test1.log')();
|
|
||||||
removeFile('datefa-default-test2.log')();
|
|
||||||
removeFile('datefa-default-test3.log')();
|
|
||||||
removeFile('datefa-default-test4.log')();
|
|
||||||
},
|
|
||||||
|
|
||||||
'should only add one `exit` listener': function (initialCount) {
|
while (count--) {
|
||||||
assert.equal(process.listeners('exit').length, initialCount + 1);
|
logfile = path.join(__dirname, 'datefa-default-test' + count + '.log');
|
||||||
},
|
dateFileAppender.configure({
|
||||||
|
filename: logfile
|
||||||
},
|
});
|
||||||
|
files.push(logfile);
|
||||||
'exit listener': {
|
|
||||||
topic: function() {
|
|
||||||
var exitListener
|
|
||||||
, openedFiles = []
|
|
||||||
, dateFileAppender = sandbox.require(
|
|
||||||
'../lib/appenders/dateFile',
|
|
||||||
{
|
|
||||||
globals: {
|
|
||||||
process: {
|
|
||||||
on: function(evt, listener) {
|
|
||||||
exitListener = listener;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
requires: {
|
|
||||||
'../streams': {
|
|
||||||
DateRollingFileStream: function(filename) {
|
|
||||||
openedFiles.push(filename);
|
|
||||||
|
|
||||||
this.end = function() {
|
|
||||||
openedFiles.shift();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
for (var i=0; i < 5; i += 1) {
|
|
||||||
dateFileAppender.appender('test' + i);
|
|
||||||
}
|
|
||||||
assert.isNotEmpty(openedFiles);
|
|
||||||
exitListener();
|
|
||||||
return openedFiles;
|
|
||||||
},
|
|
||||||
'should close all open files': function(openedFiles) {
|
|
||||||
assert.isEmpty(openedFiles);
|
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
|
|
||||||
'with default settings': {
|
after(function(done) {
|
||||||
topic: function() {
|
async.forEach(files, remove, done);
|
||||||
var that = this,
|
});
|
||||||
testFile = path.join(__dirname, 'date-appender-default.log'),
|
|
||||||
appender = require('../lib/appenders/dateFile').appender(testFile),
|
|
||||||
logger = log4js.getLogger('default-settings');
|
|
||||||
log4js.clearAppenders();
|
|
||||||
log4js.addAppender(appender, 'default-settings');
|
|
||||||
|
|
||||||
logger.info("This should be in the file.");
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
fs.readFile(testFile, "utf8", that.callback);
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
},
|
|
||||||
teardown: removeFile('date-appender-default.log'),
|
|
||||||
|
|
||||||
'should write to the file': function(contents) {
|
it('should only add one `exit` listener', function () {
|
||||||
assert.include(contents, 'This should be in the file');
|
process.listeners('exit').length.should.be.below(initialListeners + 2);
|
||||||
},
|
});
|
||||||
|
|
||||||
'should use the basic layout': function(contents) {
|
});
|
||||||
assert.match(
|
|
||||||
contents,
|
describe('exit listener', function() {
|
||||||
/\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}\] \[INFO\] default-settings - /
|
var openedFiles = [];
|
||||||
);
|
|
||||||
|
before(function() {
|
||||||
|
var exitListener
|
||||||
|
, dateFileAppender = sandbox.require(
|
||||||
|
'../lib/appenders/dateFile',
|
||||||
|
{
|
||||||
|
globals: {
|
||||||
|
process: {
|
||||||
|
on: function(evt, listener) {
|
||||||
|
exitListener = listener;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
requires: {
|
||||||
|
'../streams': {
|
||||||
|
DateRollingFileStream: function(filename) {
|
||||||
|
openedFiles.push(filename);
|
||||||
|
|
||||||
|
this.end = function() {
|
||||||
|
openedFiles.shift();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
for (var i=0; i < 5; i += 1) {
|
||||||
|
dateFileAppender.configure({
|
||||||
|
filename: 'test' + i
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
openedFiles.should.not.be.empty;
|
||||||
}
|
exitListener();
|
||||||
}).addBatch({
|
});
|
||||||
'configure': {
|
|
||||||
'with dateFileAppender': {
|
it('should close all open files', function() {
|
||||||
topic: function() {
|
openedFiles.should.be.empty;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with default settings', function() {
|
||||||
|
var contents;
|
||||||
|
|
||||||
|
before(function(done) {
|
||||||
|
var testFile = path.join(__dirname, 'date-appender-default.log'),
|
||||||
|
log4js = require('../lib/log4js'),
|
||||||
|
logger = log4js.getLogger('default-settings');
|
||||||
|
|
||||||
|
log4js.configure({
|
||||||
|
appenders: {
|
||||||
|
"date": { type: "dateFile", filename: testFile }
|
||||||
|
},
|
||||||
|
categories: {
|
||||||
|
default: { level: "debug", appenders: [ "date" ] }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.info("This should be in the file.");
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
fs.readFile(testFile, "utf8", function(err, data) {
|
||||||
|
contents = data;
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
remove('date-appender-default.log', done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should write to the file', function() {
|
||||||
|
contents.should.include('This should be in the file');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use the basic layout', function() {
|
||||||
|
contents.should.match(
|
||||||
|
/\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}\] \[INFO\] default-settings - /
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('configure', function() {
|
||||||
|
describe('with dateFileAppender', function() {
|
||||||
|
var contents;
|
||||||
|
|
||||||
|
before(function(done) {
|
||||||
var log4js = require('../lib/log4js')
|
var log4js = require('../lib/log4js')
|
||||||
, logger;
|
, logger = log4js.getLogger('tests');
|
||||||
|
|
||||||
//this config file defines one file appender (to ./date-file-test.log)
|
//this config file defines one file appender (to ./date-file-test.log)
|
||||||
//and sets the log level for "tests" to WARN
|
//and sets the log level for "tests" to WARN
|
||||||
log4js.configure('test/with-dateFile.json');
|
log4js.configure('test/with-dateFile.json');
|
||||||
logger = log4js.getLogger('tests');
|
|
||||||
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(path.join(__dirname, 'date-file-test.log'), 'utf8', this.callback);
|
fs.readFile(path.join(__dirname, 'date-file-test.log'), 'utf8', function(err, data) {
|
||||||
},
|
contents = data;
|
||||||
teardown: removeFile('date-file-test.log'),
|
done(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
remove('date-file-test.log', done);
|
||||||
|
});
|
||||||
|
|
||||||
'should load appender configuration from a json file': function(err, contents) {
|
it('should load appender configuration from a json file', function() {
|
||||||
assert.include(contents, 'this should be written to the file' + require('os').EOL);
|
contents.should.include('this should be written to the file' + require('os').EOL);
|
||||||
assert.equal(contents.indexOf('this should not be written to the file'), -1);
|
contents.should.not.include('this should not be written to the file');
|
||||||
}
|
});
|
||||||
},
|
});
|
||||||
'with options.alwaysIncludePattern': {
|
|
||||||
topic: function() {
|
describe('with options.alwaysIncludePattern', function() {
|
||||||
var self = this
|
var contents, thisTime;
|
||||||
, log4js = require('../lib/log4js')
|
|
||||||
|
before(function(done) {
|
||||||
|
var log4js = require('../lib/log4js')
|
||||||
, format = require('../lib/date_format')
|
, format = require('../lib/date_format')
|
||||||
, logger
|
, logger
|
||||||
, options = {
|
, options = {
|
||||||
"appenders": [
|
"appenders": {
|
||||||
{
|
"datefile": {
|
||||||
"category": "tests",
|
|
||||||
"type": "dateFile",
|
"type": "dateFile",
|
||||||
"filename": "test/date-file-test",
|
"filename": "test/date-file-test",
|
||||||
"pattern": "-from-MM-dd.log",
|
"pattern": "-from-MM-dd.log",
|
||||||
@@ -156,63 +176,45 @@ vows.describe('../lib/appenders/dateFile').addBatch({
|
|||||||
"type": "messagePassThrough"
|
"type": "messagePassThrough"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
}
|
categories: { default: { level: "debug", appenders: [ "datefile" ] } }
|
||||||
, thisTime = format.asString(options.appenders[0].pattern, new Date());
|
};
|
||||||
fs.writeFileSync(
|
thisTime = format.asString(options.appenders.datefile.pattern, new Date());
|
||||||
|
|
||||||
|
fs.writeFile(
|
||||||
path.join(__dirname, 'date-file-test' + thisTime),
|
path.join(__dirname, 'date-file-test' + thisTime),
|
||||||
"this is existing data" + require('os').EOL,
|
"this is existing data" + require('os').EOL,
|
||||||
'utf8'
|
'utf8',
|
||||||
);
|
function(err) {
|
||||||
log4js.clearAppenders();
|
log4js.configure(options);
|
||||||
log4js.configure(options);
|
logger = log4js.getLogger('tests');
|
||||||
logger = log4js.getLogger('tests');
|
logger.warn('this should be written to the file with the appended date');
|
||||||
logger.warn('this should be written to the file with the appended date');
|
//wait for filesystem to catch up
|
||||||
this.teardown = removeFile('date-file-test' + thisTime);
|
setTimeout(function() {
|
||||||
//wait for filesystem to catch up
|
fs.readFile(
|
||||||
setTimeout(function() {
|
path.join(__dirname, 'date-file-test' + thisTime),
|
||||||
fs.readFile(path.join(__dirname, 'date-file-test' + thisTime), 'utf8', self.callback);
|
'utf8',
|
||||||
}, 100);
|
function(err, data) {
|
||||||
},
|
contents = data;
|
||||||
'should create file with the correct pattern': function(contents) {
|
done(err);
|
||||||
assert.include(contents, 'this should be written to the file with the appended date');
|
|
||||||
},
|
|
||||||
'should not overwrite the file on open (bug found in issue #132)': function(contents) {
|
|
||||||
assert.include(contents, 'this is existing data');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'with cwd option': {
|
|
||||||
topic: function() {
|
|
||||||
var fileOpened,
|
|
||||||
appender = sandbox.require(
|
|
||||||
'../lib/appenders/dateFile',
|
|
||||||
{ requires:
|
|
||||||
{ '../streams':
|
|
||||||
{ DateRollingFileStream:
|
|
||||||
function(file) {
|
|
||||||
fileOpened = file;
|
|
||||||
return {
|
|
||||||
on: function() {},
|
|
||||||
end: function() {}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
}
|
}, 100);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
appender.configure(
|
});
|
||||||
{
|
|
||||||
filename: "whatever.log",
|
after(function(done) {
|
||||||
maxLogSize: 10
|
remove('date-file-test' + thisTime, done);
|
||||||
},
|
});
|
||||||
{ cwd: '/absolute/path/to' }
|
|
||||||
);
|
it('should create file with the correct pattern', function() {
|
||||||
return fileOpened;
|
contents.should.include('this should be written to the file with the appended date');
|
||||||
},
|
});
|
||||||
'should prepend options.cwd to config.filename': function(fileOpened) {
|
|
||||||
assert.equal(fileOpened, "/absolute/path/to/whatever.log");
|
it('should not overwrite the file on open (bug found in issue #132)', function() {
|
||||||
}
|
contents.should.include('this is existing data');
|
||||||
}
|
});
|
||||||
|
});
|
||||||
}
|
});
|
||||||
}).exportTo(module);
|
});
|
||||||
|
|||||||
@@ -1,22 +1,19 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
|
, async = require('async')
|
||||||
, path = require('path')
|
, path = require('path')
|
||||||
, sandbox = require('sandboxed-module')
|
, sandbox = require('sandboxed-module')
|
||||||
, log4js = require('../lib/log4js')
|
, log4js = require('../lib/log4js')
|
||||||
, should = require('should');
|
, should = require('should');
|
||||||
|
|
||||||
function remove(filename) {
|
function remove(filename, cb) {
|
||||||
try {
|
fs.unlink(filename, function(err) { cb(); });
|
||||||
fs.unlinkSync(filename);
|
|
||||||
} catch (e) {
|
|
||||||
//doesn't really matter if it failed
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('log4js fileAppender', function() {
|
describe('log4js fileAppender', function() {
|
||||||
|
|
||||||
describe('adding multiple fileAppenders', function() {
|
describe('adding multiple fileAppenders', function() {
|
||||||
var initialCount, listenersCount;
|
var files = [], initialCount, listenersCount;
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
var logfile
|
var logfile
|
||||||
@@ -28,12 +25,17 @@ describe('log4js fileAppender', function() {
|
|||||||
while (count--) {
|
while (count--) {
|
||||||
logfile = path.join(__dirname, '/fa-default-test' + count + '.log');
|
logfile = path.join(__dirname, '/fa-default-test' + count + '.log');
|
||||||
config.appenders["file" + count] = { type: "file", filename: logfile };
|
config.appenders["file" + count] = { type: "file", filename: logfile };
|
||||||
|
files.push(logfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
log4js.configure(config);
|
log4js.configure(config);
|
||||||
|
|
||||||
listenersCount = process.listeners('exit').length;
|
listenersCount = process.listeners('exit').length;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
async.forEach(files, remove, done);
|
||||||
|
});
|
||||||
|
|
||||||
it('does not add more than one `exit` listeners', function () {
|
it('does not add more than one `exit` listeners', function () {
|
||||||
listenersCount.should.be.below(initialCount + 2);
|
listenersCount.should.be.below(initialCount + 2);
|
||||||
@@ -83,34 +85,38 @@ describe('log4js fileAppender', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('with default fileAppender settings', function() {
|
describe('with default fileAppender settings', function() {
|
||||||
var fileContents;
|
var fileContents
|
||||||
|
, testFile = path.join(__dirname, '/fa-default-test.log');
|
||||||
|
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
var that = this
|
var logger = log4js.getLogger('default-settings');
|
||||||
, testFile = path.join(__dirname, '/fa-default-test.log')
|
|
||||||
, logger = log4js.getLogger('default-settings');
|
|
||||||
|
|
||||||
remove(testFile);
|
remove(testFile, function() {
|
||||||
|
|
||||||
log4js.configure({
|
log4js.configure({
|
||||||
appenders: {
|
appenders: {
|
||||||
"file": { type: "file", filename: testFile }
|
"file": { type: "file", filename: testFile }
|
||||||
},
|
},
|
||||||
categories: {
|
categories: {
|
||||||
default: { level: "debug", appenders: [ "file" ] }
|
default: { level: "debug", appenders: [ "file" ] }
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.info("This should be in the file.");
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
fs.readFile(testFile, "utf8", function(err, contents) {
|
|
||||||
if (!err) {
|
|
||||||
fileContents = contents;
|
|
||||||
}
|
}
|
||||||
done(err);
|
|
||||||
});
|
});
|
||||||
}, 100);
|
|
||||||
|
logger.info("This should be in the file.");
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
fs.readFile(testFile, "utf8", function(err, contents) {
|
||||||
|
if (!err) {
|
||||||
|
fileContents = contents;
|
||||||
|
}
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
remove(testFile, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should write log messages to the file', function() {
|
it('should write log messages to the file', function() {
|
||||||
@@ -127,24 +133,32 @@ describe('log4js fileAppender', function() {
|
|||||||
describe('with a max file size and no backups', function() {
|
describe('with a max file size and no backups', function() {
|
||||||
var testFile = path.join(__dirname, '/fa-maxFileSize-test.log');
|
var testFile = path.join(__dirname, '/fa-maxFileSize-test.log');
|
||||||
|
|
||||||
before(function() {
|
before(function(done) {
|
||||||
var logger = log4js.getLogger('max-file-size');
|
var logger = log4js.getLogger('max-file-size');
|
||||||
|
|
||||||
remove(testFile);
|
async.forEach([
|
||||||
remove(testFile + '.1');
|
testFile,
|
||||||
|
testFile + '.1'
|
||||||
|
], remove, function() {
|
||||||
|
|
||||||
//log file of 100 bytes maximum, no backups
|
//log file of 100 bytes maximum, no backups
|
||||||
log4js.configure({
|
log4js.configure({
|
||||||
appenders: {
|
appenders: {
|
||||||
"file": { type: "file", filename: testFile, maxLogSize: 100, backups: 0 }
|
"file": { type: "file", filename: testFile, maxLogSize: 100, backups: 0 }
|
||||||
},
|
},
|
||||||
categories: {
|
categories: {
|
||||||
default: { level: "debug", appenders: [ "file" ] }
|
default: { level: "debug", appenders: [ "file" ] }
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
logger.info("This is the first log message.");
|
||||||
|
logger.info("This is an intermediate log message.");
|
||||||
|
logger.info("This is the second log message.");
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
logger.info("This is the first log message.");
|
});
|
||||||
logger.info("This is an intermediate log message.");
|
|
||||||
logger.info("This is the second log message.");
|
after(function(done) {
|
||||||
|
async.forEach([ testFile, testFile + '.1' ], remove, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('log file', function() {
|
describe('log file', function() {
|
||||||
@@ -177,26 +191,32 @@ describe('log4js fileAppender', function() {
|
|||||||
describe('with a max file size and 2 backups', function() {
|
describe('with a max file size and 2 backups', function() {
|
||||||
var testFile = path.join(__dirname, '/fa-maxFileSize-with-backups-test.log');
|
var testFile = path.join(__dirname, '/fa-maxFileSize-with-backups-test.log');
|
||||||
|
|
||||||
before(function() {
|
before(function(done) {
|
||||||
var logger = log4js.getLogger('max-file-size-backups');
|
var logger = log4js.getLogger('max-file-size-backups');
|
||||||
remove(testFile);
|
|
||||||
remove(testFile+'.1');
|
|
||||||
remove(testFile+'.2');
|
|
||||||
|
|
||||||
//log file of 50 bytes maximum, 2 backups
|
|
||||||
log4js.configure({
|
|
||||||
appenders: {
|
|
||||||
"file": { type: "file", filename: testFile, maxLogSize: 50, backups: 2 }
|
|
||||||
},
|
|
||||||
categories: {
|
|
||||||
default: { level: "debug", appenders: [ "file" ] }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.info("This is the first log message.");
|
async.forEach([
|
||||||
logger.info("This is the second log message.");
|
testFile,
|
||||||
logger.info("This is the third log message.");
|
testFile+'.1',
|
||||||
logger.info("This is the fourth log message.");
|
testFile+'.2'
|
||||||
|
], remove, function() {
|
||||||
|
|
||||||
|
//log file of 50 bytes maximum, 2 backups
|
||||||
|
log4js.configure({
|
||||||
|
appenders: {
|
||||||
|
"file": { type: "file", filename: testFile, maxLogSize: 50, backups: 2 }
|
||||||
|
},
|
||||||
|
categories: {
|
||||||
|
default: { level: "debug", appenders: [ "file" ] }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.info("This is the first log message.");
|
||||||
|
logger.info("This is the second log message.");
|
||||||
|
logger.info("This is the third log message.");
|
||||||
|
logger.info("This is the fourth log message.");
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('the log files', function() {
|
describe('the log files', function() {
|
||||||
@@ -219,6 +239,10 @@ describe('log4js fileAppender', function() {
|
|||||||
}, 200);
|
}, 200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
async.forEach(logFiles, remove, done);
|
||||||
|
});
|
||||||
|
|
||||||
it('should be 3', function () {
|
it('should be 3', function () {
|
||||||
logFiles.should.have.length(3);
|
logFiles.should.have.length(3);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"appenders": [
|
"appenders": {
|
||||||
{
|
"dateFile": {
|
||||||
"category": "tests",
|
|
||||||
"type": "dateFile",
|
"type": "dateFile",
|
||||||
"filename": "test/date-file-test.log",
|
"filename": "test/date-file-test.log",
|
||||||
"pattern": "-from-MM-dd",
|
"pattern": "-from-MM-dd",
|
||||||
@@ -9,9 +8,9 @@
|
|||||||
"type": "messagePassThrough"
|
"type": "messagePassThrough"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
},
|
||||||
|
|
||||||
"levels": {
|
"categories": {
|
||||||
"tests": "WARN"
|
"default": { "level": "WARN", "appenders": [ "dateFile" ] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user