Diffstat (limited to 'frontend/gamma/js/MochiKit/Logging.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/MochiKit/Logging.js | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/frontend/gamma/js/MochiKit/Logging.js b/frontend/gamma/js/MochiKit/Logging.js index f00996b..8b06e0b 100644 --- a/frontend/gamma/js/MochiKit/Logging.js +++ b/frontend/gamma/js/MochiKit/Logging.js | |||
@@ -1,262 +1,262 @@ | |||
1 | /*** | 1 | /*** |
2 | 2 | ||
3 | MochiKit.Logging 1.5 | 3 | MochiKit.Logging 1.5 |
4 | 4 | ||
5 | See <http://mochikit.com/> for documentation, downloads, license, etc. | 5 | See <http://mochikit.com/> for documentation, downloads, license, etc. |
6 | 6 | ||
7 | (c) 2005 Bob Ippolito. All rights Reserved. | 7 | (c) 2005 Bob Ippolito. All rights Reserved. |
8 | 8 | ||
9 | ***/ | 9 | ***/ |
10 | 10 | ||
11 | MochiKit.Base._module('Logging', '1.5', ['Base']); | 11 | MochiKit.Base.module(MochiKit, 'Logging', '1.5', ['Base']); |
12 | 12 | ||
13 | /** @id MochiKit.Logging.LogMessage */ | 13 | /** @id MochiKit.Logging.LogMessage */ |
14 | MochiKit.Logging.LogMessage = function (num, level, info) { | 14 | MochiKit.Logging.LogMessage = function (num, level, info) { |
15 | this.num = num; | 15 | this.num = num; |
16 | this.level = level; | 16 | this.level = level; |
17 | this.info = info; | 17 | this.info = info; |
18 | this.timestamp = new Date(); | 18 | this.timestamp = new Date(); |
19 | }; | 19 | }; |
20 | 20 | ||
21 | MochiKit.Logging.LogMessage.prototype = { | 21 | MochiKit.Logging.LogMessage.prototype = { |
22 | /** @id MochiKit.Logging.LogMessage.prototype.repr */ | 22 | /** @id MochiKit.Logging.LogMessage.prototype.repr */ |
23 | repr: function () { | 23 | repr: function () { |
24 | var m = MochiKit.Base; | 24 | var m = MochiKit.Base; |
25 | return 'LogMessage(' + | 25 | return 'LogMessage(' + |
26 | m.map( | 26 | m.map( |
27 | m.repr, | 27 | m.repr, |
28 | [this.num, this.level, this.info] | 28 | [this.num, this.level, this.info] |
29 | ).join(', ') + ')'; | 29 | ).join(', ') + ')'; |
30 | }, | 30 | }, |
31 | /** @id MochiKit.Logging.LogMessage.prototype.toString */ | 31 | /** @id MochiKit.Logging.LogMessage.prototype.toString */ |
32 | toString: MochiKit.Base.forwardCall("repr") | 32 | toString: MochiKit.Base.forwardCall("repr") |
33 | }; | 33 | }; |
34 | 34 | ||
35 | MochiKit.Base.update(MochiKit.Logging, { | 35 | MochiKit.Base.update(MochiKit.Logging, { |
36 | /** @id MochiKit.Logging.logLevelAtLeast */ | 36 | /** @id MochiKit.Logging.logLevelAtLeast */ |
37 | logLevelAtLeast: function (minLevel) { | 37 | logLevelAtLeast: function (minLevel) { |
38 | var self = MochiKit.Logging; | 38 | var self = MochiKit.Logging; |
39 | if (typeof(minLevel) == 'string') { | 39 | if (typeof(minLevel) == 'string') { |
40 | minLevel = self.LogLevel[minLevel]; | 40 | minLevel = self.LogLevel[minLevel]; |
41 | } | 41 | } |
42 | return function (msg) { | 42 | return function (msg) { |
43 | var msgLevel = msg.level; | 43 | var msgLevel = msg.level; |
44 | if (typeof(msgLevel) == 'string') { | 44 | if (typeof(msgLevel) == 'string') { |
45 | msgLevel = self.LogLevel[msgLevel]; | 45 | msgLevel = self.LogLevel[msgLevel]; |
46 | } | 46 | } |
47 | return msgLevel >= minLevel; | 47 | return msgLevel >= minLevel; |
48 | }; | 48 | }; |
49 | }, | 49 | }, |
50 | 50 | ||
51 | /** @id MochiKit.Logging.isLogMessage */ | 51 | /** @id MochiKit.Logging.isLogMessage */ |
52 | isLogMessage: function (/* ... */) { | 52 | isLogMessage: function (/* ... */) { |
53 | var LogMessage = MochiKit.Logging.LogMessage; | 53 | var LogMessage = MochiKit.Logging.LogMessage; |
54 | for (var i = 0; i < arguments.length; i++) { | 54 | for (var i = 0; i < arguments.length; i++) { |
55 | if (!(arguments[i] instanceof LogMessage)) { | 55 | if (!(arguments[i] instanceof LogMessage)) { |
56 | return false; | 56 | return false; |
57 | } | 57 | } |
58 | } | 58 | } |
59 | return true; | 59 | return true; |
60 | }, | 60 | }, |
61 | 61 | ||
62 | /** @id MochiKit.Logging.compareLogMessage */ | 62 | /** @id MochiKit.Logging.compareLogMessage */ |
63 | compareLogMessage: function (a, b) { | 63 | compareLogMessage: function (a, b) { |
64 | return MochiKit.Base.compare([a.level, a.info], [b.level, b.info]); | 64 | return MochiKit.Base.compare([a.level, a.info], [b.level, b.info]); |
65 | }, | 65 | }, |
66 | 66 | ||
67 | /** @id MochiKit.Logging.alertListener */ | 67 | /** @id MochiKit.Logging.alertListener */ |
68 | alertListener: function (msg) { | 68 | alertListener: function (msg) { |
69 | alert( | 69 | alert( |
70 | "num: " + msg.num + | 70 | "num: " + msg.num + |
71 | "\nlevel: " + msg.level + | 71 | "\nlevel: " + msg.level + |
72 | "\ninfo: " + msg.info.join(" ") | 72 | "\ninfo: " + msg.info.join(" ") |
73 | ); | 73 | ); |
74 | } | 74 | } |
75 | 75 | ||
76 | }); | 76 | }); |
77 | 77 | ||
78 | /** @id MochiKit.Logging.Logger */ | 78 | /** @id MochiKit.Logging.Logger */ |
79 | MochiKit.Logging.Logger = function (/* optional */maxSize) { | 79 | MochiKit.Logging.Logger = function (/* optional */maxSize) { |
80 | this.counter = 0; | 80 | this.counter = 0; |
81 | if (typeof(maxSize) == 'undefined' || maxSize === null) { | 81 | if (typeof(maxSize) == 'undefined' || maxSize === null) { |
82 | maxSize = -1; | 82 | maxSize = -1; |
83 | } | 83 | } |
84 | this.maxSize = maxSize; | 84 | this.maxSize = maxSize; |
85 | this._messages = []; | 85 | this._messages = []; |
86 | this.listeners = {}; | 86 | this.listeners = {}; |
87 | this.useNativeConsole = false; | 87 | this.useNativeConsole = false; |
88 | }; | 88 | }; |
89 | 89 | ||
90 | MochiKit.Logging.Logger.prototype = { | 90 | MochiKit.Logging.Logger.prototype = { |
91 | /** @id MochiKit.Logging.Logger.prototype.clear */ | 91 | /** @id MochiKit.Logging.Logger.prototype.clear */ |
92 | clear: function () { | 92 | clear: function () { |
93 | this._messages.splice(0, this._messages.length); | 93 | this._messages.splice(0, this._messages.length); |
94 | }, | 94 | }, |
95 | 95 | ||
96 | /** @id MochiKit.Logging.Logger.prototype.logToConsole */ | 96 | /** @id MochiKit.Logging.Logger.prototype.logToConsole */ |
97 | logToConsole: function (msg) { | 97 | logToConsole: function (msg) { |
98 | if (typeof(window) != "undefined" && window.console | 98 | if (typeof(window) != "undefined" && window.console |
99 | && window.console.log) { | 99 | && window.console.log) { |
100 | // Safari and FireBug 0.4 | 100 | // Safari and FireBug 0.4 |
101 | // Percent replacement is a workaround for cute Safari crashing bug | 101 | // Percent replacement is a workaround for cute Safari crashing bug |
102 | window.console.log(msg.replace(/%/g, '\uFF05')); | 102 | window.console.log(msg.replace(/%/g, '\uFF05')); |
103 | } else if (typeof(opera) != "undefined" && opera.postError) { | 103 | } else if (typeof(opera) != "undefined" && opera.postError) { |
104 | // Opera | 104 | // Opera |
105 | opera.postError(msg); | 105 | opera.postError(msg); |
106 | } else if (typeof(Debug) != "undefined" && Debug.writeln) { | 106 | } else if (typeof(Debug) != "undefined" && Debug.writeln) { |
107 | // IE Web Development Helper (?) | 107 | // IE Web Development Helper (?) |
108 | // http://www.nikhilk.net/Entry.aspx?id=93 | 108 | // http://www.nikhilk.net/Entry.aspx?id=93 |
109 | Debug.writeln(msg); | 109 | Debug.writeln(msg); |
110 | } else if (typeof(debug) != "undefined" && debug.trace) { | 110 | } else if (typeof(debug) != "undefined" && debug.trace) { |
111 | // Atlas framework (?) | 111 | // Atlas framework (?) |
112 | // http://www.nikhilk.net/Entry.aspx?id=93 | 112 | // http://www.nikhilk.net/Entry.aspx?id=93 |
113 | debug.trace(msg); | 113 | debug.trace(msg); |
114 | } | 114 | } |
115 | }, | 115 | }, |
116 | 116 | ||
117 | /** @id MochiKit.Logging.Logger.prototype.dispatchListeners */ | 117 | /** @id MochiKit.Logging.Logger.prototype.dispatchListeners */ |
118 | dispatchListeners: function (msg) { | 118 | dispatchListeners: function (msg) { |
119 | for (var k in this.listeners) { | 119 | for (var k in this.listeners) { |
120 | var pair = this.listeners[k]; | 120 | var pair = this.listeners[k]; |
121 | if (pair.ident != k || (pair[0] && !pair[0](msg))) { | 121 | if (pair.ident != k || (pair[0] && !pair[0](msg))) { |
122 | continue; | 122 | continue; |
123 | } | 123 | } |
124 | pair[1](msg); | 124 | pair[1](msg); |
125 | } | 125 | } |
126 | }, | 126 | }, |
127 | 127 | ||
128 | /** @id MochiKit.Logging.Logger.prototype.addListener */ | 128 | /** @id MochiKit.Logging.Logger.prototype.addListener */ |
129 | addListener: function (ident, filter, listener) { | 129 | addListener: function (ident, filter, listener) { |
130 | if (typeof(filter) == 'string') { | 130 | if (typeof(filter) == 'string') { |
131 | filter = MochiKit.Logging.logLevelAtLeast(filter); | 131 | filter = MochiKit.Logging.logLevelAtLeast(filter); |
132 | } | 132 | } |
133 | var entry = [filter, listener]; | 133 | var entry = [filter, listener]; |
134 | entry.ident = ident; | 134 | entry.ident = ident; |
135 | this.listeners[ident] = entry; | 135 | this.listeners[ident] = entry; |
136 | }, | 136 | }, |
137 | 137 | ||
138 | /** @id MochiKit.Logging.Logger.prototype.removeListener */ | 138 | /** @id MochiKit.Logging.Logger.prototype.removeListener */ |
139 | removeListener: function (ident) { | 139 | removeListener: function (ident) { |
140 | delete this.listeners[ident]; | 140 | delete this.listeners[ident]; |
141 | }, | 141 | }, |
142 | 142 | ||
143 | /** @id MochiKit.Logging.Logger.prototype.baseLog */ | 143 | /** @id MochiKit.Logging.Logger.prototype.baseLog */ |
144 | baseLog: function (level, message/*, ...*/) { | 144 | baseLog: function (level, message/*, ...*/) { |
145 | if (typeof(level) == "number") { | 145 | if (typeof(level) == "number") { |
146 | if (level >= MochiKit.Logging.LogLevel.FATAL) { | 146 | if (level >= MochiKit.Logging.LogLevel.FATAL) { |
147 | level = 'FATAL'; | 147 | level = 'FATAL'; |
148 | } else if (level >= MochiKit.Logging.LogLevel.ERROR) { | 148 | } else if (level >= MochiKit.Logging.LogLevel.ERROR) { |
149 | level = 'ERROR'; | 149 | level = 'ERROR'; |
150 | } else if (level >= MochiKit.Logging.LogLevel.WARNING) { | 150 | } else if (level >= MochiKit.Logging.LogLevel.WARNING) { |
151 | level = 'WARNING'; | 151 | level = 'WARNING'; |
152 | } else if (level >= MochiKit.Logging.LogLevel.INFO) { | 152 | } else if (level >= MochiKit.Logging.LogLevel.INFO) { |
153 | level = 'INFO'; | 153 | level = 'INFO'; |
154 | } else { | 154 | } else { |
155 | level = 'DEBUG'; | 155 | level = 'DEBUG'; |
156 | } | 156 | } |
157 | } | 157 | } |
158 | var msg = new MochiKit.Logging.LogMessage( | 158 | var msg = new MochiKit.Logging.LogMessage( |
159 | this.counter, | 159 | this.counter, |
160 | level, | 160 | level, |
161 | MochiKit.Base.extend(null, arguments, 1) | 161 | MochiKit.Base.extend(null, arguments, 1) |
162 | ); | 162 | ); |
163 | this._messages.push(msg); | 163 | this._messages.push(msg); |
164 | this.dispatchListeners(msg); | 164 | this.dispatchListeners(msg); |
165 | if (this.useNativeConsole) { | 165 | if (this.useNativeConsole) { |
166 | this.logToConsole(msg.level + ": " + msg.info.join(" ")); | 166 | this.logToConsole(msg.level + ": " + msg.info.join(" ")); |
167 | } | 167 | } |
168 | this.counter += 1; | 168 | this.counter += 1; |
169 | while (this.maxSize >= 0 && this._messages.length > this.maxSize) { | 169 | while (this.maxSize >= 0 && this._messages.length > this.maxSize) { |
170 | this._messages.shift(); | 170 | this._messages.shift(); |
171 | } | 171 | } |
172 | }, | 172 | }, |
173 | 173 | ||
174 | /** @id MochiKit.Logging.Logger.prototype.getMessages */ | 174 | /** @id MochiKit.Logging.Logger.prototype.getMessages */ |
175 | getMessages: function (howMany) { | 175 | getMessages: function (howMany) { |
176 | var firstMsg = 0; | 176 | var firstMsg = 0; |
177 | if (!(typeof(howMany) == 'undefined' || howMany === null)) { | 177 | if (!(typeof(howMany) == 'undefined' || howMany === null)) { |
178 | firstMsg = Math.max(0, this._messages.length - howMany); | 178 | firstMsg = Math.max(0, this._messages.length - howMany); |
179 | } | 179 | } |
180 | return this._messages.slice(firstMsg); | 180 | return this._messages.slice(firstMsg); |
181 | }, | 181 | }, |
182 | 182 | ||
183 | /** @id MochiKit.Logging.Logger.prototype.getMessageText */ | 183 | /** @id MochiKit.Logging.Logger.prototype.getMessageText */ |
184 | getMessageText: function (howMany) { | 184 | getMessageText: function (howMany) { |
185 | if (typeof(howMany) == 'undefined' || howMany === null) { | 185 | if (typeof(howMany) == 'undefined' || howMany === null) { |
186 | howMany = 30; | 186 | howMany = 30; |
187 | } | 187 | } |
188 | var messages = this.getMessages(howMany); | 188 | var messages = this.getMessages(howMany); |
189 | if (messages.length) { | 189 | if (messages.length) { |
190 | var lst = map(function (m) { | 190 | var lst = MochiKit.Base.map(function (m) { |
191 | return '\n [' + m.num + '] ' + m.level + ': ' + m.info.join(' '); | 191 | return '\n [' + m.num + '] ' + m.level + ': ' + m.info.join(' '); |
192 | }, messages); | 192 | }, messages); |
193 | lst.unshift('LAST ' + messages.length + ' MESSAGES:'); | 193 | lst.unshift('LAST ' + messages.length + ' MESSAGES:'); |
194 | return lst.join(''); | 194 | return lst.join(''); |
195 | } | 195 | } |
196 | return ''; | 196 | return ''; |
197 | }, | 197 | }, |
198 | 198 | ||
199 | /** @id MochiKit.Logging.Logger.prototype.debuggingBookmarklet */ | 199 | /** @id MochiKit.Logging.Logger.prototype.debuggingBookmarklet */ |
200 | debuggingBookmarklet: function (inline) { | 200 | debuggingBookmarklet: function (inline) { |
201 | if (typeof(MochiKit.LoggingPane) == "undefined") { | 201 | if (typeof(MochiKit.LoggingPane) == "undefined") { |
202 | alert(this.getMessageText()); | 202 | alert(this.getMessageText()); |
203 | } else { | 203 | } else { |
204 | MochiKit.LoggingPane.createLoggingPane(inline || false); | 204 | MochiKit.LoggingPane.createLoggingPane(inline || false); |
205 | } | 205 | } |
206 | } | 206 | } |
207 | }; | 207 | }; |
208 | 208 | ||
209 | MochiKit.Logging.__new__ = function () { | 209 | MochiKit.Logging.__new__ = function () { |
210 | this.LogLevel = { | 210 | this.LogLevel = { |
211 | ERROR: 40, | 211 | ERROR: 40, |
212 | FATAL: 50, | 212 | FATAL: 50, |
213 | WARNING: 30, | 213 | WARNING: 30, |
214 | INFO: 20, | 214 | INFO: 20, |
215 | DEBUG: 10 | 215 | DEBUG: 10 |
216 | }; | 216 | }; |
217 | 217 | ||
218 | var m = MochiKit.Base; | 218 | var m = MochiKit.Base; |
219 | m.registerComparator("LogMessage", | 219 | m.registerComparator("LogMessage", |
220 | this.isLogMessage, | 220 | this.isLogMessage, |
221 | this.compareLogMessage | 221 | this.compareLogMessage |
222 | ); | 222 | ); |
223 | 223 | ||
224 | var partial = m.partial; | 224 | var partial = m.partial; |
225 | 225 | ||
226 | var Logger = this.Logger; | 226 | var Logger = this.Logger; |
227 | var baseLog = Logger.prototype.baseLog; | 227 | var baseLog = Logger.prototype.baseLog; |
228 | m.update(this.Logger.prototype, { | 228 | m.update(this.Logger.prototype, { |
229 | debug: partial(baseLog, 'DEBUG'), | 229 | debug: partial(baseLog, 'DEBUG'), |
230 | log: partial(baseLog, 'INFO'), | 230 | log: partial(baseLog, 'INFO'), |
231 | error: partial(baseLog, 'ERROR'), | 231 | error: partial(baseLog, 'ERROR'), |
232 | fatal: partial(baseLog, 'FATAL'), | 232 | fatal: partial(baseLog, 'FATAL'), |
233 | warning: partial(baseLog, 'WARNING') | 233 | warning: partial(baseLog, 'WARNING') |
234 | }); | 234 | }); |
235 | 235 | ||
236 | // indirectly find logger so it can be replaced | 236 | // indirectly find logger so it can be replaced |
237 | var self = this; | 237 | var self = this; |
238 | var connectLog = function (name) { | 238 | var connectLog = function (name) { |
239 | return function () { | 239 | return function () { |
240 | self.logger[name].apply(self.logger, arguments); | 240 | self.logger[name].apply(self.logger, arguments); |
241 | }; | 241 | }; |
242 | }; | 242 | }; |
243 | 243 | ||
244 | /** @id MochiKit.Logging.log */ | 244 | /** @id MochiKit.Logging.log */ |
245 | this.log = connectLog('log'); | 245 | this.log = connectLog('log'); |
246 | /** @id MochiKit.Logging.logError */ | 246 | /** @id MochiKit.Logging.logError */ |
247 | this.logError = connectLog('error'); | 247 | this.logError = connectLog('error'); |
248 | /** @id MochiKit.Logging.logDebug */ | 248 | /** @id MochiKit.Logging.logDebug */ |
249 | this.logDebug = connectLog('debug'); | 249 | this.logDebug = connectLog('debug'); |
250 | /** @id MochiKit.Logging.logFatal */ | 250 | /** @id MochiKit.Logging.logFatal */ |
251 | this.logFatal = connectLog('fatal'); | 251 | this.logFatal = connectLog('fatal'); |
252 | /** @id MochiKit.Logging.logWarning */ | 252 | /** @id MochiKit.Logging.logWarning */ |
253 | this.logWarning = connectLog('warning'); | 253 | this.logWarning = connectLog('warning'); |
254 | this.logger = new Logger(); | 254 | this.logger = new Logger(); |
255 | this.logger.useNativeConsole = true; | 255 | this.logger.useNativeConsole = true; |
256 | 256 | ||
257 | m.nameFunctions(this); | 257 | m.nameFunctions(this); |
258 | }; | 258 | }; |
259 | 259 | ||
260 | MochiKit.Logging.__new__(); | 260 | MochiKit.Logging.__new__(); |
261 | 261 | ||
262 | MochiKit.Base._exportSymbols(this, MochiKit.Logging); | 262 | MochiKit.Base._exportSymbols(this, MochiKit.Logging); |