diff --git a/README.md b/README.md index 737010f..412d950 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # 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) 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. diff --git a/lib/log4js.js b/lib/log4js.js index 4cd886e..b48302f 100644 --- a/lib/log4js.js +++ b/lib/log4js.js @@ -249,22 +249,15 @@ function getDefaultLogger () { } function findConfiguration() { - //add current directory onto the list of configPaths - var paths = ['.'].concat(require.paths); - //add this module's directory to the end of the list, so that we pick up the default config - paths.push(__dirname); - var pathsWithConfig = paths.filter( function (pathToCheck) { - try { - fs.statSync(path.join(pathToCheck, "log4js.json")); - return true; - } catch (e) { - return false; - } - }); - if (pathsWithConfig.length > 0) { - return path.join(pathsWithConfig[0], 'log4js.json'); + var path; + try { + path = require.resolve('log4js.json'); + } catch (e) { + //file not found. default to the one in the log4js module. + path = __dirname + '/log4js.json'; } - return undefined; + + return path; } function loadConfigurationFile(filename) { diff --git a/package.json b/package.json index 45db398..2d11b9d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "log4js", - "version": "0.3.8", + "version": "0.3.9", "description": "Port of Log4js to work with node.", "keywords": [ "logging", @@ -13,7 +13,7 @@ "bugs": { "web": "http://github.com/csausdev/log4js-node/issues" }, - "engines": [ "node >=0.1.100" ], + "engines": [ "node >=0.4" ], "scripts": { "test": "vows test/*.js" }, diff --git a/test/logging.js b/test/logging.js index 724e345..02658d1 100644 --- a/test/logging.js +++ b/test/logging.js @@ -264,7 +264,7 @@ vows.describe('log4js').addBatch({ 'default setup': { topic: function() { - var pathsChecked = [], + var pathLoaded, appenderEvent, logger, modulePath = require('path').normalize(__dirname + '/../lib/log4js.json'), @@ -273,17 +273,9 @@ vows.describe('log4js').addBatch({ return require('fs').readdirSync(dir); }, readFileSync: function (file, encoding) { - assert.equal(file, modulePath); + pathLoaded = file; assert.equal(encoding, 'utf8'); 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 = { @@ -307,18 +299,12 @@ vows.describe('log4js').addBatch({ logger = log4js.getLogger('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) { - var pathsChecked = args[0]; - expectedPaths = ['log4js.json'].concat( - require.paths.map(function(item) { - return item + '/log4js.json'; - }), - args[2] - ); - assert.deepEqual(pathsChecked, expectedPaths); + 'should use require.resolve to find log4js.json': function(args) { + var pathLoaded = args[0], modulePath = args[2]; + assert.equal(pathLoaded, modulePath); }, 'should configure log4js from first log4js.json found': function(args) {