Permalink
Browse files

Fixed errors and updated examples.

  • Loading branch information...
fabianishere committed Feb 27, 2012
1 parent 2506852 commit 029518a0bc64c6efb1447b55e63c33e1b0d4f8bb
Showing with 27 additions and 17 deletions.
  1. +5 −3 lib/handler/console.js
  2. +8 −4 lib/handler/file.js
  3. +8 −8 lib/logger.js
  4. +2 −1 test/filehandler.js
  5. +4 −1 test/helloworld.js
View
@@ -1,15 +1,17 @@
var SimpleFormatter = require('../formatter/simple'),
- fs = require('fs');
+ Level = require('../level');
/**
* This {@link Handler} publishes log records to <code>STDERR</code>.
* By default the {@link SimpleFormatter} is used to generate brief summaries.
*
* @author Fabian M.
*/
-module.exports = function() {
+module.exports = function(level) {
+ level = level || Level.FINEST;
var formatter = this.formatter = new SimpleFormatter();
this.publish = function(logrecord) {
- console.error(formatter.format(logrecord));
+ if (logrecord.level.value >= level.value)
+ console.error(formatter.format(logrecord));
};
};
View
@@ -1,4 +1,6 @@
-var SimpleFormatter = require('../formatter/simple');
+var SimpleFormatter = require('../formatter/simple'),
+ Level = require('../level'),
+ fs = require('fs');
/**
* This {@link Handler} publishes log records to a file.
@@ -7,10 +9,12 @@ var SimpleFormatter = require('../formatter/simple');
* @param path The path to the file to log in.
* @author Fabian M.
*/
-module.exports = function(path) {
+module.exports = function(path, level) {
+ level = level || Level.FINEST;
var formatter = this.formatter = new SimpleFormatter();
- var file = fs.open(path, 'w');
+ var file = fs.openSync(path, 'w');
this.publish = function(logrecord) {
- fs.writeSync(file, formatter.format(logrecord));
+ if (logrecord.level.value >= level.value)
+ fs.writeSync(file, formatter.format(logrecord));
};
};
View
@@ -24,7 +24,7 @@ var Logger = function(name) {
/**
* List that contains the current {@link Handler}s.
*/
- this.handlers = [new ConsoleHandler()];
+ this.handlers = [];
this.name = name;
this.levelValue = Level.INFO.value;
@@ -138,7 +138,7 @@ Logger.prototype.log = function(record, msg) {
* @param msg The string message (or a key in the message catalog)
*/
Logger.prototype.severe = function(msg) {
- if (Level.SEVERE.value < module.exports.Logger.levelValue) {
+ if (Level.SEVERE.value < Logger.levelValue) {
return;
}
@@ -153,7 +153,7 @@ Logger.prototype.severe = function(msg) {
* @param msg The string message (or a key in the message catalog)
*/
Logger.prototype.warning = function(msg) {
- if (Level.WARNING.value < module.exports.Logger.levelValue) {
+ if (Level.WARNING.value < Logger.levelValue) {
return;
}
@@ -167,7 +167,7 @@ Logger.prototype.warning = function(msg) {
* @param msg The string message (or a key in the message catalog)
*/
Logger.prototype.info = function(msg) {
- if (Level.INFO.value < module.exports.Logger.levelValue) {
+ if (Level.INFO.value < Logger.levelValue) {
return;
}
@@ -181,7 +181,7 @@ Logger.prototype.info = function(msg) {
* @param msg The string message (or a key in the message catalog)
*/
Logger.prototype.config = function(msg) {
- if (Level.CONFIG.value < module.exports.Logger.levelValue) {
+ if (Level.CONFIG.value < Logger.levelValue) {
return;
}
@@ -195,7 +195,7 @@ Logger.prototype.config = function(msg) {
* @param msg The string message (or a key in the message catalog)
*/
Logger.prototype.fine = function(msg) {
- if (Level.FINE.value < module.exports.Logger.levelValue) {
+ if (Level.FINE.value < Logger.levelValue) {
return;
}
@@ -209,7 +209,7 @@ Logger.prototype.fine = function(msg) {
* @param msg The string message (or a key in the message catalog)
*/
Logger.prototype.finer = function(msg) {
- if (Level.FINER.value < module.exports.Logger.levelValue) {
+ if (Level.FINER.value < Logger.levelValue) {
return;
}
@@ -224,7 +224,7 @@ Logger.prototype.finer = function(msg) {
* @param msg The string message (or a key in the message catalog)
*/
Logger.prototype.finest = function(msg) {
- if (Level.FINEST.value < module.exports.Logger.levelValue) {
+ if (Level.FINEST.value < Logger.levelValue) {
return;
}
View
@@ -4,6 +4,7 @@
* @author Fabian M.
*/
var FileHandler = require('../lib/handler/file')
-var logger = require('../lib/logger').getLogger("HelloWorldService").addHandler(new FileHandler("file.log"));
+var logger = require('../lib/logger').getLogger("HelloWorld");
+logger.addHandler(new FileHandler("file.log"));
logger.info("This will be printed to a file");
View
@@ -3,7 +3,10 @@
*
* @author Fabian M.
*/
-var logger = require('../lib/logger').getLogger("HelloWorld");
+var logger = require('../lib/logger').getLogger("HelloWorld"),
+ ConsoleHandler = require('../lib/handler/console');
+
+logger.addHandler(new ConsoleHandler());
logger.severe("Hello world");
logger.warning("Hello world");

0 comments on commit 029518a

Please sign in to comment.