1 /* ************************************************************************
3 qooxdoo - the new era of web development
8 2006 by STZ-IDA, Germany, http://www.stz-ida.de
11 LGPL 2.1: http://www.gnu.org/licenses/lgpl.html
14 * Til Schneider (til132)
16 ************************************************************************ */
18 /* ************************************************************************
23 ************************************************************************ */
26 * An appender. Does the actual logging.
28 qx.OO.defineClass("qx.dev.log.Appender", qx.dev.log.LogEventProcessor,
30 qx.dev.log.LogEventProcessor.call(this);
34 /** Whether the logger name and log level should be included in the formatted log message. */
35 qx.OO.addProperty({ name:"useLongFormat", type:"boolean", defaultValue:true, allowNull:false });
39 qx.Proto.handleLogEvent = function(evt) {
40 if (this.decideLogEvent(evt) != qx.dev.log.Filter.DENY) {
41 this.appendLogEvent(evt);
47 * Appends a log event to the log.
49 * @param evt {Map} The event to append.
51 qx.Proto.appendLogEvent = function(evt) {
52 throw new Error("appendLogEvent is abstract");
57 * Formats a log event.
59 * @param evt {Map} The log event to format.
60 * @return {string} The formatted event.
62 qx.Proto.formatLogEvent = function(evt) {
63 var Logger = qx.dev.log.Logger;
67 // Append the time stamp
68 var time = new String(new Date().getTime() - qx._LOADSTART);
69 while (time.length < 6) {
75 if (this.getUseLongFormat()) {
77 case Logger.LEVEL_DEBUG: text += " DEBUG: "; break;
78 case Logger.LEVEL_INFO: text += " INFO: "; break;
79 case Logger.LEVEL_WARN: text += " WARN: "; break;
80 case Logger.LEVEL_ERROR: text += " ERROR: "; break;
81 case Logger.LEVEL_FATAL: text += " FATAL: "; break;
89 for (var i = 0; i < evt.indent; i++) {
94 // Append the logger name and instance
95 if (this.getUseLongFormat()) {
96 text += evt.logger.getName();
97 if (evt.instanceId != null) {
98 text += "[" + evt.instanceId + "]";
103 // Append the message
104 if (typeof evt.message == "string") {
107 // The message is an object -> Log a dump of the object
108 var obj = evt.message;
110 text += "Object is null";
112 text += "--- Object: " + obj + " ---\n";
113 var attrArr = new Array();
115 for (var attr in obj) {
119 text += indent + " [not readable: " + exc + "]\n";
122 for (var i = 0; i < attrArr.length; i++) {
124 text += indent + " " + attrArr[i] + "=" + obj[attrArr[i]] + "\n";
127 text += indent + " " + attrArr[i] + "=[not readable: " + exc + "]\n";
130 text += indent + "--- End of object ---";
134 // Append the throwable
135 if (evt.throwable != null) {
136 var thr = evt.throwable;
138 if (thr.name == null) {
141 text += ": " + thr.name;
143 if (thr.message != null) {
144 text += " - " + thr.message;
146 if (thr.number != null) {
147 text += " (#" + thr.number + ")";
150 if (thr.stack != null) {
151 text += "\n" + this._beautyStackTrace(thr.stack);
160 * Beautifies a stack trace.
162 * @param stack {string} the stack trace to beautify.
163 * @return {string} the beautified stack trace.
165 qx.Proto._beautyStackTrace = function(stack) {
166 // e.g. "()@http://localhost:8080/webcomponent-test-SNAPSHOT/webcomponent/js/com/ptvag/webcomponent/common/log/Logger:253"
167 var lineRe = /@(.+):(\d+)$/gm;
170 var scriptDir = "/script/";
171 while ((hit = lineRe.exec(stack)) != null) {
174 var jsPos = url.indexOf(scriptDir);
175 var className = (jsPos == -1) ? url : url.substring(jsPos + scriptDir.length).replace(/\//g, ".");
177 var lineNumber = hit[2];
178 out += " at " + className + ":" + lineNumber + "\n";