more linting
This commit is contained in:
parent
20f80ff775
commit
def0e8e371
@ -1,8 +1,9 @@
|
|||||||
var vows = require('vows'),
|
"use strict";
|
||||||
assert = require('assert'),
|
var vows = require('vows')
|
||||||
path = require('path'),
|
, assert = require('assert')
|
||||||
fs = require('fs'),
|
, path = require('path')
|
||||||
log4js = require('../lib/log4js');
|
, fs = require('fs')
|
||||||
|
, log4js = require('../lib/log4js');
|
||||||
|
|
||||||
function removeFile(filename) {
|
function removeFile(filename) {
|
||||||
return function() {
|
return function() {
|
||||||
@ -15,119 +16,126 @@ function removeFile(filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vows.describe('../lib/appenders/dateFile').addBatch({
|
vows.describe('../lib/appenders/dateFile').addBatch({
|
||||||
'appender': {
|
'appender': {
|
||||||
'adding multiple dateFileAppenders': {
|
'adding multiple dateFileAppenders': {
|
||||||
topic: function () {
|
topic: function () {
|
||||||
var listenersCount = process.listeners('exit').length,
|
var listenersCount = process.listeners('exit').length,
|
||||||
dateFileAppender = require('../lib/appenders/dateFile'),
|
dateFileAppender = require('../lib/appenders/dateFile'),
|
||||||
count = 5,
|
count = 5,
|
||||||
logfile;
|
logfile;
|
||||||
|
|
||||||
while (count--) {
|
while (count--) {
|
||||||
logfile = path.join(__dirname, 'datefa-default-test' + count + '.log');
|
logfile = path.join(__dirname, 'datefa-default-test' + count + '.log');
|
||||||
log4js.addAppender(dateFileAppender.appender(logfile));
|
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) {
|
|
||||||
assert.equal(process.listeners('exit').length, initialCount + 1);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'with default settings': {
|
|
||||||
topic: function() {
|
|
||||||
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) {
|
|
||||||
assert.include(contents, 'This should be in the file');
|
|
||||||
},
|
|
||||||
|
|
||||||
'should use the basic layout': function(contents) {
|
|
||||||
assert.match(contents, /\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}\] \[INFO\] default-settings - /);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
assert.equal(process.listeners('exit').length, initialCount + 1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'with default settings': {
|
||||||
|
topic: function() {
|
||||||
|
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) {
|
||||||
|
assert.include(contents, 'This should be in the file');
|
||||||
|
},
|
||||||
|
|
||||||
|
'should use the basic layout': function(contents) {
|
||||||
|
assert.match(
|
||||||
|
contents,
|
||||||
|
/\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}\] \[INFO\] default-settings - /
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}).addBatch({
|
}).addBatch({
|
||||||
'configure': {
|
'configure': {
|
||||||
'with dateFileAppender': {
|
'with dateFileAppender': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
var log4js = require('../lib/log4js')
|
var log4js = require('../lib/log4js')
|
||||||
, logger;
|
, logger;
|
||||||
//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 = 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', this.callback);
|
||||||
},
|
},
|
||||||
teardown: removeFile('date-file-test.log'),
|
teardown: removeFile('date-file-test.log'),
|
||||||
|
|
||||||
'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' + require('os').EOL);
|
assert.include(contents, 'this should be written to the file' + require('os').EOL);
|
||||||
assert.equal(contents.indexOf('this should not be written to the file'), -1);
|
assert.equal(contents.indexOf('this should not be written to the file'), -1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'with options.alwaysIncludePattern': {
|
'with options.alwaysIncludePattern': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
var log4js = require('../lib/log4js')
|
var log4js = require('../lib/log4js')
|
||||||
, format = require('../lib/date_format')
|
, format = require('../lib/date_format')
|
||||||
, logger
|
, logger
|
||||||
, options = {
|
, options = {
|
||||||
"appenders": [
|
"appenders": [
|
||||||
{
|
{
|
||||||
"category": "tests",
|
"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",
|
||||||
"alwaysIncludePattern": true,
|
"alwaysIncludePattern": true,
|
||||||
"layout": {
|
"layout": {
|
||||||
"type": "messagePassThrough"
|
"type": "messagePassThrough"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
, thisTime = format.asString(options.appenders[0].pattern, new Date());
|
, thisTime = format.asString(options.appenders[0].pattern, new Date());
|
||||||
fs.writeFileSync(path.join(__dirname, 'date-file-test' + thisTime), "this is existing data" + require('os').EOL, 'utf8');
|
fs.writeFileSync(
|
||||||
log4js.clearAppenders();
|
path.join(__dirname, 'date-file-test' + thisTime),
|
||||||
log4js.configure(options);
|
"this is existing data" + require('os').EOL,
|
||||||
logger = log4js.getLogger('tests');
|
'utf8'
|
||||||
logger.warn('this should be written to the file with the appended date');
|
);
|
||||||
|
log4js.clearAppenders();
|
||||||
|
log4js.configure(options);
|
||||||
|
logger = log4js.getLogger('tests');
|
||||||
|
logger.warn('this should be written to the file with the appended date');
|
||||||
this.teardown = removeFile('date-file-test' + thisTime);
|
this.teardown = removeFile('date-file-test' + thisTime);
|
||||||
fs.readFile(path.join(__dirname, 'date-file-test' + thisTime), 'utf8', this.callback);
|
fs.readFile(path.join(__dirname, 'date-file-test' + thisTime), 'utf8', this.callback);
|
||||||
},
|
},
|
||||||
'should create file with the correct pattern': function(contents) {
|
'should create file with the correct pattern': function(contents) {
|
||||||
assert.include(contents, 'this should be written to the file with the appended date');
|
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) {
|
'should not overwrite the file on open (bug found in issue #132)': function(contents) {
|
||||||
assert.include(contents, 'this is existing data');
|
assert.include(contents, 'this is existing data');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}).exportTo(module);
|
}).exportTo(module);
|
||||||
|
Loading…
Reference in New Issue
Block a user