fixed to work with node 0.5.x
This commit is contained in:
parent
53a481d4da
commit
12e71bda4e
@ -1,5 +1,7 @@
|
|||||||
# log4js-node
|
# log4js-node
|
||||||
|
|
||||||
|
NOTE: v0.3.8 of log4js is the last that will work with node versions older than 0.4. To use v0.3.9 you will need node 0.4 or later.
|
||||||
|
|
||||||
This is a conversion of the [log4js](http://log4js.berlios.de/index.html)
|
This is a conversion of the [log4js](http://log4js.berlios.de/index.html)
|
||||||
framework to work with [node](http://nodejs.org). I've mainly stripped out the browser-specific code
|
framework to work with [node](http://nodejs.org). I've mainly stripped out the browser-specific code
|
||||||
and tidied up some of the javascript. It includes a basic file logger, with log rolling based on file size, and also replaces node's console.log functions.
|
and tidied up some of the javascript. It includes a basic file logger, with log rolling based on file size, and also replaces node's console.log functions.
|
||||||
|
@ -249,22 +249,15 @@ function getDefaultLogger () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function findConfiguration() {
|
function findConfiguration() {
|
||||||
//add current directory onto the list of configPaths
|
var path;
|
||||||
var paths = ['.'].concat(require.paths);
|
try {
|
||||||
//add this module's directory to the end of the list, so that we pick up the default config
|
path = require.resolve('log4js.json');
|
||||||
paths.push(__dirname);
|
} catch (e) {
|
||||||
var pathsWithConfig = paths.filter( function (pathToCheck) {
|
//file not found. default to the one in the log4js module.
|
||||||
try {
|
path = __dirname + '/log4js.json';
|
||||||
fs.statSync(path.join(pathToCheck, "log4js.json"));
|
|
||||||
return true;
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (pathsWithConfig.length > 0) {
|
|
||||||
return path.join(pathsWithConfig[0], 'log4js.json');
|
|
||||||
}
|
}
|
||||||
return undefined;
|
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadConfigurationFile(filename) {
|
function loadConfigurationFile(filename) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "log4js",
|
"name": "log4js",
|
||||||
"version": "0.3.8",
|
"version": "0.3.9",
|
||||||
"description": "Port of Log4js to work with node.",
|
"description": "Port of Log4js to work with node.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"logging",
|
"logging",
|
||||||
@ -13,7 +13,7 @@
|
|||||||
"bugs": {
|
"bugs": {
|
||||||
"web": "http://github.com/csausdev/log4js-node/issues"
|
"web": "http://github.com/csausdev/log4js-node/issues"
|
||||||
},
|
},
|
||||||
"engines": [ "node >=0.1.100" ],
|
"engines": [ "node >=0.4" ],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vows test/*.js"
|
"test": "vows test/*.js"
|
||||||
},
|
},
|
||||||
|
@ -264,7 +264,7 @@ vows.describe('log4js').addBatch({
|
|||||||
|
|
||||||
'default setup': {
|
'default setup': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
var pathsChecked = [],
|
var pathLoaded,
|
||||||
appenderEvent,
|
appenderEvent,
|
||||||
logger,
|
logger,
|
||||||
modulePath = require('path').normalize(__dirname + '/../lib/log4js.json'),
|
modulePath = require('path').normalize(__dirname + '/../lib/log4js.json'),
|
||||||
@ -273,17 +273,9 @@ vows.describe('log4js').addBatch({
|
|||||||
return require('fs').readdirSync(dir);
|
return require('fs').readdirSync(dir);
|
||||||
},
|
},
|
||||||
readFileSync: function (file, encoding) {
|
readFileSync: function (file, encoding) {
|
||||||
assert.equal(file, modulePath);
|
pathLoaded = file;
|
||||||
assert.equal(encoding, 'utf8');
|
assert.equal(encoding, 'utf8');
|
||||||
return '{ "appenders" : [ { "type": "console", "layout": { "type": "messagePassThrough" }} ] }';
|
return '{ "appenders" : [ { "type": "console", "layout": { "type": "messagePassThrough" }} ] }';
|
||||||
},
|
|
||||||
statSync: function (path) {
|
|
||||||
pathsChecked.push(path);
|
|
||||||
if (path === modulePath) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
throw new Error("no such file");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fakeConsole = {
|
fakeConsole = {
|
||||||
@ -307,18 +299,12 @@ vows.describe('log4js').addBatch({
|
|||||||
|
|
||||||
logger = log4js.getLogger('a-test');
|
logger = log4js.getLogger('a-test');
|
||||||
logger.debug("this is a test");
|
logger.debug("this is a test");
|
||||||
return [ pathsChecked, appenderEvent, modulePath ];
|
return [ pathLoaded, appenderEvent, modulePath ];
|
||||||
},
|
},
|
||||||
|
|
||||||
'should check current directory, require paths, and finally the module dir for log4js.json': function(args) {
|
'should use require.resolve to find log4js.json': function(args) {
|
||||||
var pathsChecked = args[0];
|
var pathLoaded = args[0], modulePath = args[2];
|
||||||
expectedPaths = ['log4js.json'].concat(
|
assert.equal(pathLoaded, modulePath);
|
||||||
require.paths.map(function(item) {
|
|
||||||
return item + '/log4js.json';
|
|
||||||
}),
|
|
||||||
args[2]
|
|
||||||
);
|
|
||||||
assert.deepEqual(pathsChecked, expectedPaths);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
'should configure log4js from first log4js.json found': function(args) {
|
'should configure log4js from first log4js.json found': function(args) {
|
||||||
|
Loading…
Reference in New Issue
Block a user