From 270ba0fcc617d4ec3cf96f8d0322f08134ef45dd Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Thu, 22 Aug 2013 08:44:36 +1000 Subject: [PATCH] added initial configuration --- lib/log4js.js | 24 +++++++++++------------- test/log4js-test.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/lib/log4js.js b/lib/log4js.js index c781a30..f92a999 100644 --- a/lib/log4js.js +++ b/lib/log4js.js @@ -20,18 +20,21 @@ *

Example:

*
  *  var logging = require('log4js');
- *  //add an appender that logs all messages to stdout.
- *  logging.addAppender(logging.consoleAppender());
- *  //add an appender that logs "some-category" to a file
- *  logging.addAppender(logging.fileAppender("file.log"), "some-category");
+ *  logging.configure({
+ *    appenders: {
+ *      "errorFile": { type: "file", filename: "error.log" }
+ *    },
+ *    categories: {
+ *      "default": { level: "ERROR", appenders: [ "errorFile" ] }
+ *    }
+ *  });
  *  //get a logger
  *  var log = logging.getLogger("some-category");
- *  log.setLevel(logging.levels.TRACE); //set the Level
  *
  *  ...
  *
  *  //call the log
- *  log.trace("trace me" );
+ *  log.error("oh noes");
  * 
* * NOTE: the authors below are the original browser-based log4js authors @@ -286,11 +289,6 @@ function restoreConsole() { */ module.exports = { getLogger: getLogger, -/* - addAppender: addAppender, - loadAppender: loadAppender, - clearAppenders: clearAppenders, -*/ configure: configure, /* replaceConsole: replaceConsole, @@ -306,6 +304,6 @@ module.exports = { }; //set ourselves up -//debug("Starting configuration"); -//configure(); +debug("Starting configuration"); +configure(defaultConfig); diff --git a/test/log4js-test.js b/test/log4js-test.js index 40742c9..6c721e9 100644 --- a/test/log4js-test.js +++ b/test/log4js-test.js @@ -288,4 +288,34 @@ describe('../lib/log4js', function() { it('should reload configuration if specified'); }); + + describe('with no configuration', function() { + var events = [] + , log4js_sandboxed = sandbox.require( + '../lib/log4js', + { + requires: { + './appenders/console': { + configure: function() { + return function(event) { events.push(event); }; + } + } + } + } + ); + + log4js_sandboxed.getLogger("blah").debug("goes to console"); + log4js_sandboxed.getLogger("yawn").trace("does not go to console"); + log4js_sandboxed.getLogger().error("also goes to console"); + + it('should log events of debug level and higher to console', function() { + events.should.have.length(2); + events[0].data[0].should.eql("goes to console"); + events[0].category.should.eql("blah"); + events[0].level.toString().should.eql("DEBUG"); + events[1].data[0].should.eql("also goes to console"); + events[1].category.should.eql("default"); + events[1].level.toString().should.eql("ERROR"); + }); + }); });