Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Go to most recent revision | 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
 
11
dojo.provide("dojo.logging.ConsoleLogger");
12
dojo.require("dojo.logging.Logger");
13
dojo.lang.extend(dojo.logging.MemoryLogHandler, {debug:function () {
14
	dojo.hostenv.println.apply(this, arguments);
15
}, info:function () {
16
	dojo.hostenv.println.apply(this, arguments);
17
}, warn:function () {
18
	dojo.hostenv.println.apply(this, arguments);
19
}, error:function () {
20
	dojo.hostenv.println.apply(this, arguments);
21
}, critical:function () {
22
	dojo.hostenv.println.apply(this, arguments);
23
}, emit:function (record) {
24
	if (!djConfig.isDebug) {
25
		return;
26
	}
27
	var funcName = null;
28
	switch (record.level) {
29
	  case 1:
30
		funcName = "debug";
31
		break;
32
	  case 2:
33
		funcName = "info";
34
		break;
35
	  case 3:
36
		funcName = "warn";
37
		break;
38
	  case 4:
39
		funcName = "error";
40
		break;
41
	  case 5:
42
		funcName = "critical";
43
		break;
44
	  default:
45
		funcName = "debug";
46
	}
47
	var logStr = String(dojo.log.getLevelName(record.level) + ": " + record.time.toLocaleTimeString()) + ": " + record.message;
48
	if (record.msgArgs && record.msgArgs.length > 0) {
49
		this[funcName].call(this, logStr, record.msgArgs);
50
	} else {
51
		this[funcName].call(this, logStr);
52
	}
53
	this.data.push(record);
54
	if (this.numRecords != -1) {
55
		while (this.data.length > this.numRecords) {
56
			this.data.shift();
57
		}
58
	}
59
}});
60
if (!dj_undef("console") && !dj_undef("info", console)) {
61
	dojo.lang.extend(dojo.logging.MemoryLogHandler, {debug:function () {
62
		console.debug.apply(this, arguments);
63
	}, info:function () {
64
		console.info.apply(this, arguments);
65
	}, warn:function () {
66
		console.warn.apply(this, arguments);
67
	}, error:function () {
68
		console.error.apply(this, arguments);
69
	}, critical:function () {
70
		console.error.apply(this, arguments);
71
	}});
72
	dojo.lang.extend(dojo.logging.Logger, {exception:function (msg, e, squelch) {
73
		var args = [msg];
74
		if (e) {
75
			msg += " : " + e.name + " " + (e.description || e.message);
76
			args.push(e);
77
		}
78
		this.logType("ERROR", args);
79
		if (!squelch) {
80
			throw e;
81
		}
82
	}});
83
}
84