1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
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());
}
|