diff options
author | Derrell Lipman <derrell@samba.org> | 2007-02-06 03:23:52 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:44:34 -0500 |
commit | ef256c958066c19bb10cbe9745bdf96b6514762d (patch) | |
tree | dbe379cb3021c5af2d1b8f74528e4fff968fc712 /webapps/qooxdoo-0.6.5-sdk/frontend/framework/source/class/qx/log/Logger.js | |
parent | a8d0f5df6266aeacdb20326094c0401618ab62e8 (diff) | |
download | samba-ef256c958066c19bb10cbe9745bdf96b6514762d.tar.gz samba-ef256c958066c19bb10cbe9745bdf96b6514762d.tar.bz2 samba-ef256c958066c19bb10cbe9745bdf96b6514762d.zip |
r21167: - Upgrade to latest released qooxdoo. This is step 1 of the upgrade process,
which involves adding the latest SDK. This new version has not 2, but 4
icon themes. In order to quiet Andrew B. who thinks that 9000+ files in a
gui api is too many (come on, disk space is free these days :-), I have
removed 3 of the 4 icon themes, leaving only the default, Nuvola. That
lowers the file count by 1/3. I'm sure Andrew still isn't happy, but I hope
he's a bit happier... Step 2 will make him happier yet.
(This used to be commit d161c1382c36238105b85d0499d5a1011f580f52)
Diffstat (limited to 'webapps/qooxdoo-0.6.5-sdk/frontend/framework/source/class/qx/log/Logger.js')
-rw-r--r-- | webapps/qooxdoo-0.6.5-sdk/frontend/framework/source/class/qx/log/Logger.js | 382 |
1 files changed, 382 insertions, 0 deletions
diff --git a/webapps/qooxdoo-0.6.5-sdk/frontend/framework/source/class/qx/log/Logger.js b/webapps/qooxdoo-0.6.5-sdk/frontend/framework/source/class/qx/log/Logger.js new file mode 100644 index 0000000000..8f16559191 --- /dev/null +++ b/webapps/qooxdoo-0.6.5-sdk/frontend/framework/source/class/qx/log/Logger.js @@ -0,0 +1,382 @@ +/* ************************************************************************ + + qooxdoo - the new era of web development + + http://qooxdoo.org + + Copyright: + 2006 STZ-IDA, Germany, http://www.stz-ida.de + + License: + LGPL: http://www.gnu.org/licenses/lgpl.html + EPL: http://www.eclipse.org/org/documents/epl-v10.php + See the LICENSE file in the project's top-level directory for details. + + Authors: + * Til Schneider (til132) + +************************************************************************ */ + +/* ************************************************************************ + +#module(core) +#module(log) +#require(qx.log.WindowAppender) +#require(qx.log.FireBugAppender) +* +************************************************************************ */ + +/** + * A logger. Logs messages of one log category. + * + * @param name {String} The category name of this logger. (Normally a class or + * package name) + * @param parentLogger {Logger} The parent logger. + */ +qx.OO.defineClass("qx.log.Logger", qx.log.LogEventProcessor, +function(name, parentLogger) { + qx.log.LogEventProcessor.call(this); + + this._name = name; + this._parentLogger = parentLogger; +}); + + +/** + * Returns the name of this logger. (Normally a class or package name) + * + * @return {String} the name. + */ +qx.Proto.getName = function() { + return this._name; +} + + +/** + * Returns the parent logger. + * + * @return {Logger} the parent logger. + */ +qx.Proto.getParentLogger = function() { + return this._parentLogger; +} + + +/** + * Indents all following log messages by one. + * <p> + * This affects all log messages. Even those of other loggers. + */ +qx.Proto.indent = function() { + qx.log.Logger._indent++; +} + + +/** + * Unindents all following log messages by one. + * <p> + * This affects all log messages. Even those of other loggers. + */ +qx.Proto.unindent = function() { + qx.log.Logger._indent--; +} + + +/** + * Adds an appender. + * <p> + * If a logger has an appender, log events will not be passed to the + * appenders of parent loggers. If you want this behaviour, also append a + * {@link ForwardAppender}. + * + * @param appender {Appender} the appender to add. + */ +qx.Proto.addAppender = function(appender) { + if (this._appenderArr == null) { + this._appenderArr = []; + } + + this._appenderArr.push(appender); +} + + +/** + * Removes an appender. + * + * @param appender {Appender} the appender to remove. + */ +qx.Proto.removeAppender = function(appender) { + if (this._appenderArr != null) { + this._appenderArr.remove(appender); + } +} + + +/** + * Removes all appenders. + */ +qx.Proto.removeAllAppenders = function() { + this._appenderArr = null; +} + + +// overridden +qx.Proto.handleLogEvent = function(evt) { + var Filter = qx.log.Filter; + + var decision = Filter.NEUTRAL; + var logger = this; + while (decision == Filter.NEUTRAL && logger != null) { + decision = logger.decideLogEvent(evt); + logger = logger.getParentLogger(); + } + + if (decision != Filter.DENY) { + this.appendLogEvent(evt); + } +} + + +/** + * Passes a log event to the appenders. If the logger has no appenders the + * event will be passed to the appenders of the parent logger, and so on. + * + * @param evt {Map} The event to append. + */ +qx.Proto.appendLogEvent = function(evt) { + if (this._appenderArr != null && this._appenderArr.length != 0) { + for (var i = 0; i < this._appenderArr.length; i++) { + this._appenderArr[i].handleLogEvent(evt); + } + } else if (this._parentLogger != null) { + this._parentLogger.appendLogEvent(evt); + } +} + + +/** + * Logs a message. + * + * @param level {Integer} the log level. + * @param msg {var} the message to log. If this is not a string, the + * object dump will be logged. + * @param instanceId {var ? null} the ID of the instance the log message comes from. + * @param exc {var ? null} the exception to log. + */ +qx.Proto.log = function(level, msg, instanceId, exc) { + var evt = { logger:this, level:level, message:msg, throwable:exc, + indent:qx.log.Logger._indent, instanceId:instanceId } + this.handleLogEvent(evt); +} + + +/** + * Logs a debug message. + * + * @param msg {var} the message to log. If this is not a string, the + * object dump will be logged. + * @param instanceId {var ? null} the ID of the instance the log message comes from. + * @param exc {var ? null} the exception to log. + */ +qx.Proto.debug = function(msg, instanceId, exc) { + this.log(qx.log.Logger.LEVEL_DEBUG, msg, instanceId, exc); +} + + +/** + * Logs an info message. + * + * @param msg {var} the message to log. If this is not a string, the + * object dump will be logged. + * @param instanceId {var ? null} the ID of the instance the log message comes from. + * @param exc {var ? null} the exception to log. + */ +qx.Proto.info = function(msg, instanceId, exc) { + this.log(qx.log.Logger.LEVEL_INFO, msg, instanceId, exc); +} + + +/** + * Logs a warning message. + * + * @param msg {var} the message to log. If this is not a string, the + * object dump will be logged. + * @param instanceId {var ? null} the ID of the instance the log message comes from. + * @param exc {var ? null} the exception to log. + */ +qx.Proto.warn = function(msg, instanceId, exc) { + this.log(qx.log.Logger.LEVEL_WARN, msg, instanceId, exc); +} + + +/** + * Logs an error message. + * + * @param msg {var} the message to log. If this is not a string, the + * object dump will be logged. + * @param instanceId {var ? null} the ID of the instance the log message comes from. + * @param exc {var ? null} the exception to log. + */ +qx.Proto.error = function(msg, instanceId, exc) { + this.log(qx.log.Logger.LEVEL_ERROR, msg, instanceId, exc); +} + + +/** + * Logs a fatal message. + * + * @param msg {var} the message to log. If this is not a string, its + * object dump will be logged. + * @param instanceId {var ? null} the ID of the instance the log message comes from. + * @param exc {var ? null} the exception to log. + */ +qx.Proto.fatal = function(msg, instanceId, exc) { + this.log(qx.log.Logger.LEVEL_FATAL, msg, instanceId, exc); +} + + +/** + * Resets the measure timer. + * + * @see #measure() + */ +qx.Proto.measureReset = function() { + if (this._totalMeasureTime != null) { + this.debug("Measure reset. Total measure time: " + this._totalMeasureTime + " ms"); + } + + this._lastMeasureTime = null; + this._totalMeasureTime = null; +} + + +/** + * Logs a debug message and measures the time since the last call of measure. + * + * @param msg {String} the message to log. + * @param instanceId {var ? null} the ID of the instance the log message comes from. + * @param exc {var ? null} the exception to log. + */ +qx.Proto.measure = function(msg, instanceId, exc) { + if (this._lastMeasureTime == null) { + msg = "(measure start) " + msg; + } else { + var delta = new Date().getTime() - this._lastMeasureTime; + + if (this._totalMeasureTime == null) { + this._totalMeasureTime = 0; + } + + this._totalMeasureTime += delta; + msg = "(passed time: " + delta + " ms) " + msg; + } + + this.debug(msg, instanceId, exc); + + this._lastMeasureTime = new Date().getTime(); +} + + +/** + * Logs the current stack trace as a debug message. + */ +qx.Proto.printStackTrace = function() { + try { + forced_exception.go; + } catch (exc) { + this.debug("Current stack trace", "", exc); + } +} + + +/** + * Returns the logger of a class. + * + * @param clazz {Function} The class of which to return the logger. + */ +qx.Class.getClassLogger = function(clazz) { + var logger = clazz._logger; + if (logger == null) { + // Get the parent logger + var classname = clazz.classname; + var splits = classname.split("."); + var currPackage = window; + var currPackageName = ""; + var parentLogger = qx.log.Logger.ROOT_LOGGER; + for (var i = 0; i < splits.length - 1; i++) { + currPackage = currPackage[splits[i]]; + currPackageName += ((i != 0) ? "." : "") + splits[i]; + + if (currPackage._logger == null) { + // This package has no logger -> Create one + currPackage._logger = new qx.log.Logger(currPackageName, parentLogger); + } + parentLogger = currPackage._logger; + } + + // Create the class logger + logger = new qx.log.Logger(classname, parentLogger); + clazz._logger = logger; + } + return logger; +} + + +/** {Integer} The current indent. */ +qx.Class._indent = 0; + +/** + * {Integer} The ALL level has the lowest possible rank and is intended to turn on + * all logging. + */ +qx.Class.LEVEL_ALL = 0; + +/** + * {Integer} The DEBUG Level designates fine-grained informational events that are + * most useful to debug an application. + */ +qx.Class.LEVEL_DEBUG = 200; + +/** + * {Integer} The INFO level designates informational messages that highlight the + * progress of the application at coarse-grained level. + */ +qx.Class.LEVEL_INFO = 500; + +/** {Integer} The WARN level designates potentially harmful situations. */ +qx.Class.LEVEL_WARN = 600; + +/** + * {Integer} The ERROR level designates error events that might still allow the + * application to continue running. + */ +qx.Class.LEVEL_ERROR = 700; + +/** + * {Integer} The FATAL level designates very severe error events that will + * presumably lead the application to abort. + */ +qx.Class.LEVEL_FATAL = 800; + +/** + * {Integer} The OFF has the highest possible rank and is intended to turn off + * logging. + */ +qx.Class.LEVEL_OFF = 1000; + + +/** + * {Logger} The root logger. This is the root of the logger tree. All loggers + * should be a child or grand child of this root logger. + * <p> + * This logger logs by default everything greater than level INFO to a log + * window. + */ +qx.Class.ROOT_LOGGER = new qx.log.Logger("root", null); +qx.Class.ROOT_LOGGER.setMinLevel(qx.log.Logger.LEVEL_DEBUG); + +if (typeof console != 'undefined' && console.debug) { + qx.Class.ROOT_LOGGER.addAppender(new qx.log.FireBugAppender()); +} else { + qx.Class.ROOT_LOGGER.addAppender(new qx.log.WindowAppender()); +} |