Permalink
Browse files

Updated..

  • Loading branch information...
1 parent cb9501b commit 29f0d87039080863d677ce458b4e0035bd89effb @fabianishere committed Jan 2, 2012
Showing with 94 additions and 81 deletions.
  1. +65 −54 lib/level.js
  2. +29 −27 lib/logger.js
View
@@ -1,10 +1,13 @@
/**
- * The {@link Level} object defines a set of standard logging levels that can be
- * used to control logging output. The logging Level objects are ordered and are
- * specified by ordered integers. Enabling logging at a given level also enables
- * logging at all higher levels. Clients should normally use the predefined
- * Level constants such as {@link Level#SEVERE}. The levels in descending order
- * are:
+ * The {@link Level} object defines a set of standard logging levels
+ * that can be used to control logging output.
+ * The logging Level objects are ordered and are
+ * specified by ordered integers.
+ * Enabling logging at a given level also enables
+ * logging at all higher levels.
+ * Clients should normally use the predefined
+ * {@link Level} constants such as {@link Level#SEVERE}.
+ * The levels in descending order are:
* <ul>
* <li>SEVERE (highest value)</li>
* <li>WARNING</li>
@@ -19,10 +22,10 @@
* The name of the {@link Level}, for example "SEVERE".
* @param value
* An integer value for the level.
- * @version 1.2
+ * @version 1.3
* @author Fabian M.
*/
-module.exports.Level = function(name, value) {
+var Level = function(name, value) {
if (typeof name != 'string' || typeof value != 'number')
return null;
/**
@@ -37,7 +40,7 @@ module.exports.Level = function(name, value) {
/**
* Converts a {@link Level} object to a string.
*/
-module.exports.Level.prototype.toString = function() {
+Level.prototype.toString = function() {
return this.value;
};
/**
@@ -46,77 +49,85 @@ module.exports.Level.prototype.toString = function() {
* @param other
* The {@link Level} to compare this {@link Level} with.
*/
-module.exports.Level.prototype.equals = function(other) {
+Level.prototype.equals = function(other) {
if (typeof other.value != 'number')
return false;
return number == other.value;
};
/**
* {@link Level#OFF} is a special level that can be used to turn off logging.
- * This level is initialized to {@link Number#MAX_VALUE}
+ * This level is initialized to {@link Number#MAX_VALUE}.
*/
-module.exports.OFF = new module.exports.Level("OFF", Number.MAX_VALUE),
+Level.OFF = new Level("OFF", Number.MAX_VALUE),
/**
- * {@link Level#SEVERE} is a message level indicating a serious failure. In
- * general {@link Level#SEVERE} messages should describe events that are of
- * considerable importance and which will prevent normal program execution. They
- * should be reasonably intelligible to end users and to system administrators.
+ * {@link Level#SEVERE} is a message level indicating a serious failure.
+ * In general {@link Level#SEVERE} messages should describe events that are of
+ * considerable importance and which will prevent normal program execution.
+ * They should be reasonably intelligible to end users and to system administrators.
* This level is initialized to 1000.
*/
-module.exports.SEVERE = new module.exports.Level("SEVERE", 1000),
+Level.SEVERE = new Level("SEVERE", 1000),
/**
- * {@link Level#WARNING} is a message level indicating a potential problem. In
- * general {@link Level#WARNING} messages should describe events that will be of
- * interest to end users or system managers, or which indicate potential
- * problems. This level is initialized to 900.
+ * {@link Level#WARNING} is a message level indicating a potential problem.
+ * In general {@link Level#WARNING} messages should describe events that will be of
+ * interest to end users or system managers, or which indicate potential problems.
+ * This level is initialized to 900.
*/
-module.exports.WARNING = new module.exports.Level("WARNING", 900),
+Level.WARNING = new Level("WARNING", 900),
/**
- * {@link Level#INFO} is a message level for informational messages. Typically
- * {@link Level#INFO} messages will be written to the console or its equivalent.
+ * {@link Level#INFO} is a message level for informational messages.
+ * Typically {@link Level#INFO} messages will be written to the console or its equivalent.
* So the {@link Level#INFO} level should only be used for reasonably
- * significant messages that will make sense to end users and system admins.
+ * significant messages that will make sense to end users and system admins.
* This level is initialized to 800.
*/
-module.exports.INFO = new module.exports.Level("INFO", 800),
+Level.INFO = new Level("INFO", 800),
/**
* {@link Level#CONFIG} is a message level for static configuration messages.
* {@link Level#CONFIG} messages are intended to provide a variety of static
- * configuration information, to assist in debugging problems that may be
- * associated with particular configurations. For example, {@link Level#CONFIG}
- * message might include the CPU type, the graphics depth, the GUI
- * look-and-feel, etc. This level is initialized to 700.
+ * configuration information, to assist in debugging problems that may be
+ * associated with particular configurations.
+ * For example, {@link Level#CONFIG}
+ * message might include the CPU type, the graphics depth, the GUI
+ * look-and-feel, etc.
+ * This level is initialized to 700.
*/
-module.exports.CONFIG = new module.exports.Level("CONFIG", 700),
+Level.CONFIG = new module.exports.Level("CONFIG", 700),
/**
- * {@link Level#FINE} is a message level providing tracing information. All of
- * {@link Level#FINE}, {@link Level#FINER}, and {@link Level#FINEST} are
- * intended for relatively detailed tracing. T The exact meaning of the three
- * levels will vary between subsystems, but in general, {@link Level#FINEST}
- * should be used for the most voluminous detailed output, {@link Level#FINER}
- * for somewhat less detailed output, and {@link Level#FINE} for the lowest
- * volume (and most important) messages. In general the {@link Level#FINE} level
- * should be used for information that will be broadly interesting to developers
- * who do not have a specialized interest in the specific subsystem.
- * {@link Level#FINE} messages might include things like minor (recoverable)
- * failures. Issues indicating potential performance problems are also worth
- * logging as {@link Level#FINE}. This level is initialized to 500.
+ * {@link Level#FINE} is a message level providing tracing information.
+ * All of {@link Level#FINE}, {@link Level#FINER}, and {@link Level#FINEST} are
+ * intended for relatively detailed tracing.
+ * The exact meaning of the three levels will vary between subsystems,
+ * but in general, {@link Level#FINEST} should be used
+ for the most voluminous detailed output, {@link Level#FINER}
+ * for somewhat less detailed output, and {@link Level#FINE} for the lowest
+ * volume (and most important) messages.
+ * In general the {@link Level#FINE} level should be used
+ * for information that will be broadly interesting to developers
+ * who do not have a specialized interest in the specific subsystem.
+ * {@link Level#FINE} messages might include things like minor (recoverable) failures.
+ * Issues indicating potential performance problems are also worth
+ * logging as {@link Level#FINE}.
+ * This level is initialized to 500.
*/
-module.exports.FINE = new module.exports.Level("FINE", 500),
+Level.FINE = new Level("FINE", 500),
/**
- * {@link Level#FINER} indicates a fairly detailed tracing message. By default
- * logging calls for entering, returning, or throwing an exception are traced at
- * this level. This level is initialized to 400.
+ * {@link Level#FINER} indicates a fairly detailed tracing message.
+ * By default logging calls for entering, returning, or throwing an
+ * exception are traced at this level.
+ * This level is initialized to 400.
*/
-module.exports.FINER = new module.exports.Level("FINER", 400),
+Level.FINER = new Level("FINER", 400),
/**
- * {@link Level#FINEST} indicates a highly detailed tracing message. This level
- * is initialized to 300.
+ * {@link Level#FINEST} indicates a highly detailed tracing message.
+ * This level is initialized to 300.
*/
-module.exports.FINEST = new module.exports.Level("FINEST", 300),
+Level.FINEST = new Level("FINEST", 300),
/**
- * {@link Level#ALL} indicates that all messages should be logged. This level is
- * initialized to {@link Number#MIN_VALUE}
+ * {@link Level#ALL} indicates that all messages should be logged.
+ * This level is initialized to {@link Number#MIN_VALUE}.
*/
-module.exports.ALL = new module.exports.Level("ALL", Number.MIN_VALUE);
+Level.ALL = new Level("ALL", Number.MIN_VALUE);
+
+module.exports = Level;
View
@@ -7,24 +7,12 @@ var ConsoleHandler = require('./handler/console.js');
*/
var loggers = new Array();
/**
- * Find or create a logger for a named subsystem.
- * If a logger has already been created with the given name it is returned,
- * otherwise a new logger is created.
- *
- * @param name The name of this logger.
- */
-module.exports.getLogger = function(name) {
- if (typeof loggers[name] != 'undefined')
- return logger[name];
- return new module.exports.Logger(name);
-};
-/**
* A {@link Logger} object is used to log messages for a specific system or application component.
*
* @param name A name for the logger.
* @author Fabian M.
*/
-module.exports.Logger = function(name) {
+var Logger = function(name) {
if (typeof name != 'string')
return null;
/**
@@ -37,6 +25,18 @@ module.exports.Logger = function(name) {
this.filter = null;
};
/**
+ * Find or create a logger for a named subsystem.
+ * If a logger has already been created with the given name it is returned,
+ * otherwise a new logger is created.
+ *
+ * @param name The name of this logger.
+ */
+Logger.getLogger = function(name) {
+ if (typeof loggers[name] != 'undefined')
+ return logger[name];
+ return new Logger(name);
+};
+/**
* {@link Logger#GLOBAL_LOGGER_NAME} is a name for the global logger.
* This name is provided as a convenience to developers who are making casual use of the Logging package.
* Developers who are making serious use of the lolevelValuegging package (for example in products) should create
@@ -45,23 +45,23 @@ module.exports.Logger = function(name) {
* The preferred way to get the global logger object is via the call
* Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).
*/
-module.exports.Logger.GLOBAL_LOGGER_NAME = "global";
+Logger.GLOBAL_LOGGER_NAME = "global";
/**
* The "global" Logger object is provided as a convenience to developers who are making casual use of
* the Logging package.
* Developers who are making serious use of the logging package (for example in products) should
* create and use their own Logger objects, with appropriate names, so that logging can be controlled
* on a suitable per-Logger granularity.
*/
-module.exports.global = module.exports.getLogger(module.exports.Logger.GLOBAL_LOGGER_NAME);
+Logger.global = getLogger(module.exports.Logger.GLOBAL_LOGGER_NAME);
/**
* Set a filter to control output on this Logger.
* After passing .SEVERthe initial "level" check, the Logger will call
* this {@link Filter} to check if a log record should really be published.
*
* @param filter The filter to set.
*/
-module.exports.Logger.prototype.setFilter = function(filter) {
+Logger.prototype.setFilter = function(filter) {
if (typeof filter != 'function')
return;
this.filter = filter;
@@ -71,7 +71,7 @@ module.exports.Logger.prototype.setFilter = function(filter) {
*
* @return a filter object (may be null)
*/
-module.exports.Logger.prototype.getFilter = function() {
+Logger.prototype.getFilter = function() {
return this.filter;
};
/**
@@ -82,7 +82,7 @@ module.exports.Logger.prototype.getFilter = function() {
*
* @param handler A logging {@link Handler}.
*/
-module.exports.Logger.prototype.addHandler = function(handler) {
+Logger.prototype.addHandler = function(handler) {
if (typeof handler != 'object')
return;
this.handlers.push(handler);
@@ -93,7 +93,7 @@ module.exports.Logger.prototype.addHandler = function(handler) {
*
* @return An array of all registered {@link Handler}s.
*/
-module.exports.Logger.prototype.getHandlers = function() {
+Logger.prototype.getHandlers = function() {
return this.handlers;
};
/**
@@ -103,7 +103,7 @@ module.exports.Logger.prototype.getHandlers = function() {
*
* @param record The {@link LogRecord} to be published.
*/
-module.exports.Logger.prototype.log = function(record, msg) {
+Logger.prototype.log = function(record, msg) {
if (typeof msg == 'undefined') {
// String is given.
if (typeof record == 'string') {
@@ -131,7 +131,7 @@ module.exports.Logger.prototype.log = function(record, msg) {
*
* @param msg The string message (or a key in the message catalog)
*/
-module.exports.Logger.prototype.severe = function(msg) {
+Logger.prototype.severe = function(msg) {
if (Level.SEVERE.value < module.exports.Logger.levelValue) {
return;
}
@@ -146,7 +146,7 @@ module.exports.Logger.prototype.severe = function(msg) {
*
* @param msg The string message (or a key in the message catalog)
*/
-module.exports.Logger.prototype.warning = function(msg) {
+Logger.prototype.warning = function(msg) {
if (Level.WARNING.value < module.exports.Logger.levelValue) {
return;
}
@@ -160,7 +160,7 @@ module.exports.Logger.prototype.warning = function(msg) {
*
* @param msg The string message (or a key in the message catalog)
*/
-module.exports.Logger.prototype.info = function(msg) {
+Logger.prototype.info = function(msg) {
if (Level.INFO.value < module.exports.Logger.levelValue) {
return;
}
@@ -174,7 +174,7 @@ module.exports.Logger.prototype.info = function(msg) {
*
* @param msg The string message (or a key in the message catalog)
*/
-module.exports.Logger.prototype.config = function(msg) {
+Logger.prototype.config = function(msg) {
if (Level.CONFIG.value < module.exports.Logger.levelValue) {
return;
}
@@ -188,7 +188,7 @@ module.exports.Logger.prototype.config = function(msg) {
*
* @param msg The string message (or a key in the message catalog)
*/
-module.exports.Logger.prototype.fine = function(msg) {
+Logger.prototype.fine = function(msg) {
if (Level.FINE.value < module.exports.Logger.levelValue) {
return;
}
@@ -202,7 +202,7 @@ module.exports.Logger.prototype.fine = function(msg) {
*
* @param msg The string message (or a key in the message catalog)
*/
-module.exports.Logger.prototype.finer = function(msg) {
+Logger.prototype.finer = function(msg) {
if (Level.FINER.value < module.exports.Logger.levelValue) {
return;
}
@@ -217,11 +217,13 @@ module.exports.Logger.prototype.finer = function(msg) {
*
* @param msg The string message (or a key in the message catalog)
*/
-module.exports.Logger.prototype.finest = function(msg) {
+Logger.prototype.finest = function(msg) {
if (Level.FINEST.value < module.exports.Logger.levelValue) {
return;
}
this.log(Level.FINEST, msg);
};
+module.exports = Logger;
+

0 comments on commit 29f0d87

Please sign in to comment.