2
* Copyright 2004 ThoughtWorks, Inc
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
var Logger = function() {
18
this.logWindow = null;
30
pendingMessages: new Array(),
34
setLogLevelThreshold: function(logLevel) {
35
this.threshold = logLevel;
36
var logWindow = this.getLogWindow()
37
if (logWindow && logWindow.setThresholdLevel) {
38
logWindow.setThresholdLevel(logLevel);
40
// NOTE: log messages will be discarded until the log window is
44
getLogWindow: function() {
45
if (this.logWindow && this.logWindow.closed) {
46
this.logWindow = null;
48
return this.logWindow;
51
openLogWindow: function() {
52
this.logWindow = window.open(
53
getDocumentBase(document) + "SeleniumLog.html?startingThreshold="+this.threshold, "SeleniumLog",
54
"width=600,height=1000,bottom=0,right=0,status,scrollbars,resizable"
56
this.logWindow.moveTo(window.screenX + 1210, window.screenY + window.outerHeight - 1400);
57
if (browserVersion.appearsToBeBrokenInitialIE6) {
58
// I would really prefer for the message to immediately appear in the log window, the instant the user requests that the log window be
59
// visible. But when I initially coded it this way, thou message simply didn't appear unless I stepped through the code with a debugger.
60
// So obviously there is some timing issue here which I don't have the patience to figure out.
61
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.");
62
this.pendingMessages.push(pendingMessage);
64
return this.logWindow;
68
if (! this.getLogWindow()) {
71
setTimeout(function(){LOG.error("Log window displayed. Logging events will now be recorded to this window.");}, 500);
74
logHook: function(logLevel, message) {
77
log: function(logLevel, message) {
78
if (this.logLevels[logLevel] < this.logLevels[this.threshold]) {
81
this.logHook(logLevel, message);
82
var logWindow = this.getLogWindow();
84
if (logWindow.append) {
85
if (logWindow.disabled) {
86
logWindow.callBack = fnBind(this.setLogLevelThreshold, this);
87
logWindow.enableButtons();
89
if (this.pendingMessages.length > 0) {
90
logWindow.append("info("+(new Date().getTime())+"): Appending missed logging messages", "info");
91
while (this.pendingMessages.length > 0) {
92
var msg = this.pendingMessages.shift();
93
logWindow.append(msg.type + "("+msg.timestamp+"): " + msg.msg, msg.type);
95
logWindow.append("info("+(new Date().getTime())+"): Done appending missed logging messages", "info");
97
logWindow.append(logLevel + "("+(new Date().getTime())+"): " + message, logLevel);
100
// TODO these logging messages are never flushed, which creates
101
// an enormous array of strings that never stops growing.
102
// there should at least be a way to clear the messages!
103
this.pendingMessages.push(new LogMessage(logLevel, message));
107
close: function(message) {
108
if (this.logWindow != null) {
110
this.logWindow.close();
113
// the window is probably closed if we get an exception here
115
this.logWindow = null;
119
debug: function(message) {
120
this.log("debug", message);
123
info: function(message) {
124
this.log("info", message);
127
warn: function(message) {
128
this.log("warn", message);
131
error: function(message) {
132
this.log("error", message);
135
exception: function(exception) {
136
this.error("Unexpected Exception: " + extractExceptionMessage(exception));
137
this.error("Exception details: " + describe(exception, ', '));
142
var LOG = new Logger();
144
var LogMessage = function(type, msg) {
147
this.timestamp = (new Date().getTime());