Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.logging.ConsoleLogger");
14
dojo.require("dojo.logging.Logger");
15
dojo.lang.extend(dojo.logging.MemoryLogHandler, {debug:function () {
16
	dojo.hostenv.println.apply(this, arguments);
17
}, info:function () {
18
	dojo.hostenv.println.apply(this, arguments);
19
}, warn:function () {
20
	dojo.hostenv.println.apply(this, arguments);
21
}, error:function () {
22
	dojo.hostenv.println.apply(this, arguments);
23
}, critical:function () {
24
	dojo.hostenv.println.apply(this, arguments);
25
}, emit:function (record) {
26
	if (!djConfig.isDebug) {
27
		return;
28
	}
29
	var funcName = null;
30
	switch (record.level) {
31
	  case 1:
32
		funcName = "debug";
33
		break;
34
	  case 2:
35
		funcName = "info";
36
		break;
37
	  case 3:
38
		funcName = "warn";
39
		break;
40
	  case 4:
41
		funcName = "error";
42
		break;
43
	  case 5:
44
		funcName = "critical";
45
		break;
46
	  default:
47
		funcName = "debug";
48
	}
49
	var logStr = String(dojo.log.getLevelName(record.level) + ": " + record.time.toLocaleTimeString()) + ": " + record.message;
50
	if (record.msgArgs && record.msgArgs.length > 0) {
51
		this[funcName].call(this, logStr, record.msgArgs);
52
	} else {
53
		this[funcName].call(this, logStr);
54
	}
55
	this.data.push(record);
56
	if (this.numRecords != -1) {
57
		while (this.data.length > this.numRecords) {
58
			this.data.shift();
59
		}
60
	}
61
}});
62
if (!dj_undef("console") && !dj_undef("info", console)) {
63
	dojo.lang.extend(dojo.logging.MemoryLogHandler, {debug:function () {
64
		console.debug.apply(this, arguments);
65
	}, info:function () {
66
		console.info.apply(this, arguments);
67
	}, warn:function () {
68
		console.warn.apply(this, arguments);
69
	}, error:function () {
70
		console.error.apply(this, arguments);
71
	}, critical:function () {
72
		console.error.apply(this, arguments);
73
	}});
74
	dojo.lang.extend(dojo.logging.Logger, {exception:function (msg, e, squelch) {
75
		var args = [msg];
76
		if (e) {
77
			msg += " : " + e.name + " " + (e.description || e.message);
78
			args.push(e);
79
		}
80
		this.logType("ERROR", args);
81
		if (!squelch) {
82
			throw e;
83
		}
84
	}});
85
}
86