[ Index ] |
|
Code source de PRADO 3.0.6 |
1 /* 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 return this.logWindow; 56 }, 57 58 show: function() { 59 if (! this.getLogWindow()) { 60 this.openLogWindow(); 61 } 62 }, 63 64 logHook: function(message, className) { 65 }, 66 67 log: function(message, className) { 68 var logWindow = this.getLogWindow(); 69 this.logHook(message, className); 70 if (logWindow) { 71 if (logWindow.append) { 72 if (this.pendingMessages.length > 0) { 73 logWindow.append("info: Appending missed logging messages", "info"); 74 while (this.pendingMessages.length > 0) { 75 var msg = this.pendingMessages.shift(); 76 logWindow.append(msg.type + ": " + msg.msg, msg.type); 77 } 78 logWindow.append("info: Done appending missed logging messages", "info"); 79 } 80 logWindow.append(className + ": " + message, className); 81 } 82 } else { 83 // uncomment this to turn on background logging 84 /* these logging messages are never flushed, which creates 85 an enormous array of strings that never stops growing. Only 86 turn this on if you need it for debugging! */ 87 //this.pendingMessages.push(new LogMessage(message, className)); 88 } 89 }, 90 91 close: function(message) { 92 if (this.logWindow != null) { 93 try { 94 this.logWindow.close(); 95 } catch (e) { 96 // swallow exception 97 // the window is probably closed if we get an exception here 98 } 99 this.logWindow = null; 100 } 101 }, 102 103 debug: function(message) { 104 this.log(message, "debug"); 105 }, 106 107 info: function(message) { 108 this.log(message, "info"); 109 }, 110 111 warn: function(message) { 112 this.log(message, "warn"); 113 }, 114 115 error: function(message) { 116 this.log(message, "error"); 117 }, 118 119 exception: function(exception) { 120 var msg = "Unexpected Exception: " + describe(exception, ', '); 121 this.error(msg); 122 } 123 124 }; 125 126 var LOG = new Logger(); 127 128 var LogMessage = function(msg, type) { 129 this.type = type; 130 this.msg = msg; 131 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |