1 |
4307
|
leinfelder
|
/*
|
2 |
|
|
* Copyright 2004 ThoughtWorks, Inc
|
3 |
|
|
*
|
4 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
|
|
* you may not use this file except in compliance with the License.
|
6 |
|
|
* You may obtain a copy of the License at
|
7 |
|
|
*
|
8 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
9 |
|
|
*
|
10 |
|
|
* Unless required by applicable law or agreed to in writing, software
|
11 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
|
|
* See the License for the specific language governing permissions and
|
14 |
|
|
* limitations under the License.
|
15 |
|
|
*/
|
16 |
|
|
|
17 |
|
|
var Logger = function() {
|
18 |
|
|
this.logWindow = null;
|
19 |
|
|
}
|
20 |
|
|
Logger.prototype = {
|
21 |
|
|
|
22 |
|
|
pendingMessages: new Array(),
|
23 |
|
|
|
24 |
|
|
setLogLevelThreshold: function(logLevel) {
|
25 |
|
|
this.pendingLogLevelThreshold = logLevel;
|
26 |
|
|
this.show();
|
27 |
|
|
// NOTE: log messages will be discarded until the log window is
|
28 |
|
|
// fully loaded.
|
29 |
|
|
},
|
30 |
|
|
|
31 |
|
|
getLogWindow: function() {
|
32 |
|
|
if (this.logWindow && this.logWindow.closed) {
|
33 |
|
|
this.logWindow = null;
|
34 |
|
|
}
|
35 |
|
|
if (this.logWindow && this.pendingLogLevelThreshold && this.logWindow.setThresholdLevel) {
|
36 |
|
|
this.logWindow.setThresholdLevel(this.pendingLogLevelThreshold);
|
37 |
|
|
|
38 |
|
|
// can't just directly log because that action would loop back
|
39 |
|
|
// to this code infinitely
|
40 |
|
|
var pendingMessage = new LogMessage("info", "Log level programmatically set to " + this.pendingLogLevelThreshold + " (presumably by driven-mode test code)");
|
41 |
|
|
this.pendingMessages.push(pendingMessage);
|
42 |
|
|
|
43 |
|
|
this.pendingLogLevelThreshold = null; // let's only go this way one time
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
return this.logWindow;
|
47 |
|
|
},
|
48 |
|
|
|
49 |
|
|
openLogWindow: function() {
|
50 |
|
|
this.logWindow = window.open(
|
51 |
|
|
getDocumentBase(document) + "SeleniumLog.html", "SeleniumLog",
|
52 |
|
|
"width=600,height=1000,bottom=0,right=0,status,scrollbars,resizable"
|
53 |
|
|
);
|
54 |
|
|
this.logWindow.moveTo(window.screenX + 1210, window.screenY + window.outerHeight - 1400);
|
55 |
|
|
if (browserVersion.appearsToBeBrokenInitialIE6) {
|
56 |
|
|
// I would really prefer for the message to immediately appear in the log window, the instant the user requests that the log window be
|
57 |
|
|
// visible. But when I initially coded it this way, thou message simply didn't appear unless I stepped through the code with a debugger.
|
58 |
|
|
// So obviously there is some timing issue here which I don't have the patience to figure out.
|
59 |
|
|
var pendingMessage = new LogMessage("warn", "You appear to be running an unpatched IE 6, which is not stable and can crash due to memory problems. We recommend you run Windows update to install a more stable version of IE.");
|
60 |
|
|
this.pendingMessages.push(pendingMessage);
|
61 |
|
|
}
|
62 |
|
|
return this.logWindow;
|
63 |
|
|
},
|
64 |
|
|
|
65 |
|
|
show: function() {
|
66 |
|
|
if (! this.getLogWindow()) {
|
67 |
|
|
this.openLogWindow();
|
68 |
|
|
}
|
69 |
|
|
setTimeout(function(){LOG.info("Log window displayed");}, 500);
|
70 |
|
|
},
|
71 |
|
|
|
72 |
|
|
logHook: function(className, message) {
|
73 |
|
|
},
|
74 |
|
|
|
75 |
|
|
log: function(className, message) {
|
76 |
|
|
var logWindow = this.getLogWindow();
|
77 |
|
|
this.logHook(className, message);
|
78 |
|
|
if (logWindow) {
|
79 |
|
|
if (logWindow.append) {
|
80 |
|
|
if (this.pendingMessages.length > 0) {
|
81 |
|
|
logWindow.append("info: Appending missed logging messages", "info");
|
82 |
|
|
while (this.pendingMessages.length > 0) {
|
83 |
|
|
var msg = this.pendingMessages.shift();
|
84 |
|
|
logWindow.append(msg.type + ": " + msg.msg, msg.type);
|
85 |
|
|
}
|
86 |
|
|
logWindow.append("info: Done appending missed logging messages", "info");
|
87 |
|
|
}
|
88 |
|
|
logWindow.append(className + ": " + message, className);
|
89 |
|
|
}
|
90 |
|
|
} else {
|
91 |
|
|
// uncomment this to turn on background logging
|
92 |
|
|
/* these logging messages are never flushed, which creates
|
93 |
|
|
an enormous array of strings that never stops growing. Only
|
94 |
|
|
turn this on if you need it for debugging! */
|
95 |
|
|
//this.pendingMessages.push(new LogMessage(className, message));
|
96 |
|
|
}
|
97 |
|
|
},
|
98 |
|
|
|
99 |
|
|
close: function(message) {
|
100 |
|
|
if (this.logWindow != null) {
|
101 |
|
|
try {
|
102 |
|
|
this.logWindow.close();
|
103 |
|
|
} catch (e) {
|
104 |
|
|
// swallow exception
|
105 |
|
|
// the window is probably closed if we get an exception here
|
106 |
|
|
}
|
107 |
|
|
this.logWindow = null;
|
108 |
|
|
}
|
109 |
|
|
},
|
110 |
|
|
|
111 |
|
|
debug: function(message) {
|
112 |
|
|
this.log("debug", message);
|
113 |
|
|
},
|
114 |
|
|
|
115 |
|
|
info: function(message) {
|
116 |
|
|
this.log("info", message);
|
117 |
|
|
},
|
118 |
|
|
|
119 |
|
|
warn: function(message) {
|
120 |
|
|
this.log("warn", message);
|
121 |
|
|
},
|
122 |
|
|
|
123 |
|
|
error: function(message) {
|
124 |
|
|
this.log("error", message);
|
125 |
|
|
},
|
126 |
|
|
|
127 |
|
|
exception: function(exception) {
|
128 |
|
|
this.error("Unexpected Exception: " + extractExceptionMessage(exception));
|
129 |
|
|
this.error("Exception details: " + describe(exception, ', '));
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
};
|
133 |
|
|
|
134 |
|
|
var LOG = new Logger();
|
135 |
|
|
|
136 |
|
|
var LogMessage = function(type, msg) {
|
137 |
|
|
this.type = type;
|
138 |
|
|
this.msg = msg;
|
139 |
|
|
}
|