http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/debug/errorreporter.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/debug/errorreporter.js b/externs/GCL/externs/goog/debug/errorreporter.js new file mode 100644 index 0000000..e869792 --- /dev/null +++ b/externs/GCL/externs/goog/debug/errorreporter.js @@ -0,0 +1,434 @@ +// Copyright 2009 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Definition of the ErrorReporter class, which creates an error + * handler that reports any errors raised to a URL. + * + */ + +goog.provide('goog.debug.ErrorReporter'); +goog.provide('goog.debug.ErrorReporter.ExceptionEvent'); + +goog.require('goog.asserts'); +goog.require('goog.debug'); +goog.require('goog.debug.Error'); +goog.require('goog.debug.ErrorHandler'); +goog.require('goog.debug.entryPointRegistry'); +goog.require('goog.events'); +goog.require('goog.events.Event'); +goog.require('goog.events.EventTarget'); +goog.require('goog.log'); +goog.require('goog.net.XhrIo'); +goog.require('goog.object'); +goog.require('goog.string'); +goog.require('goog.uri.utils'); +goog.require('goog.userAgent'); + + + +/** + * Constructs an error reporter. Internal Use Only. To install an error + * reporter see the {@see #install} method below. + * + * @param {string} handlerUrl The URL to which all errors will be reported. + * @param {function(!Error, !Object<string, string>)=} + * opt_contextProvider When a report is to be sent to the server, + * this method will be called, and given an opportunity to modify the + * context object before submission to the server. + * @param {boolean=} opt_noAutoProtect Whether to automatically add handlers for + * onerror and to protect entry points. If apps have other error reporting + * facilities, it may make sense for them to set these up themselves and use + * the ErrorReporter just for transmission of reports. + * @constructor + * @extends {goog.events.EventTarget} + */ +goog.debug.ErrorReporter = function( + handlerUrl, opt_contextProvider, opt_noAutoProtect) { + goog.debug.ErrorReporter.base(this, 'constructor'); + + /** + * Context provider, if one was provided. + * @type {?function(!Error, !Object<string, string>)} + * @private + */ + this.contextProvider_ = opt_contextProvider || null; + + /** + * The string prefix of any optional context parameters logged with the error. + * @private {string} + */ + this.contextPrefix_ = 'context.'; + + /** + * The number of bytes after which the ErrorReporter truncates the POST body. + * If null, the ErrorReporter won't truncate the body. + * @private {?number} + */ + this.truncationLimit_ = null; + + /** + * Additional arguments to append to URL before sending XHR. + * @private {!Object<string,string>} + */ + this.additionalArguments_ = {}; + + /** + * XHR sender. + * @type {function(string, string, string, (Object|goog.structs.Map)=)} + * @private + */ + this.xhrSender_ = goog.debug.ErrorReporter.defaultXhrSender; + + /** + * The URL at which all errors caught by this handler will be logged. + * + * @type {string} + * @private + */ + this.handlerUrl_ = handlerUrl; + + if (goog.debug.ErrorReporter.ALLOW_AUTO_PROTECT) { + if (!opt_noAutoProtect) { + /** + * The internal error handler used to catch all errors. + * + * @private {goog.debug.ErrorHandler} + */ + this.errorHandler_ = null; + + this.setup_(); + } + } else if (!opt_noAutoProtect) { + goog.asserts.fail( + 'opt_noAutoProtect cannot be false while ' + + 'goog.debug.ErrorReporter.ALLOW_AUTO_PROTECT is false. Setting ' + + 'ALLOW_AUTO_PROTECT to false removes the necessary auto-protect code ' + + 'in compiled/optimized mode.'); + } +}; +goog.inherits(goog.debug.ErrorReporter, goog.events.EventTarget); + + +/** + * @define {boolean} If true, the code that provides additional entry point + * protection and setup is exposed in this file. Set to false to avoid + * bringing in a lot of code from ErrorHandler and entryPointRegistry in + * compiled mode. + */ +goog.define('goog.debug.ErrorReporter.ALLOW_AUTO_PROTECT', true); + + + +/** + * Event broadcast when an exception is logged. + * @param {Error} error The exception that was was reported. + * @param {!Object<string, string>} context The context values sent to the + * server alongside this error. + * @constructor + * @extends {goog.events.Event} + * @final + */ +goog.debug.ErrorReporter.ExceptionEvent = function(error, context) { + goog.events.Event.call(this, goog.debug.ErrorReporter.ExceptionEvent.TYPE); + + /** + * The error that was reported. + * @type {Error} + */ + this.error = error; + + /** + * Context values sent to the server alongside this report. + * @type {!Object<string, string>} + */ + this.context = context; +}; +goog.inherits(goog.debug.ErrorReporter.ExceptionEvent, goog.events.Event); + + +/** + * Event type for notifying of a logged exception. + * @type {string} + */ +goog.debug.ErrorReporter.ExceptionEvent.TYPE = + goog.events.getUniqueId('exception'); + + +/** + * Extra headers for the error-reporting XHR. + * @type {Object|goog.structs.Map|undefined} + * @private + */ +goog.debug.ErrorReporter.prototype.extraHeaders_; + + +/** + * Logging object. + * + * @type {goog.log.Logger} + * @private + */ +goog.debug.ErrorReporter.logger_ = + goog.log.getLogger('goog.debug.ErrorReporter'); + + +/** + * Installs an error reporter to catch all JavaScript errors raised. + * + * @param {string} loggingUrl The URL to which the errors caught will be + * reported. + * @param {function(!Error, !Object<string, string>)=} + * opt_contextProvider When a report is to be sent to the server, + * this method will be called, and given an opportunity to modify the + * context object before submission to the server. + * @param {boolean=} opt_noAutoProtect Whether to automatically add handlers for + * onerror and to protect entry points. If apps have other error reporting + * facilities, it may make sense for them to set these up themselves and use + * the ErrorReporter just for transmission of reports. + * @return {!goog.debug.ErrorReporter} The error reporter. + */ +goog.debug.ErrorReporter.install = function( + loggingUrl, opt_contextProvider, opt_noAutoProtect) { + var instance = new goog.debug.ErrorReporter( + loggingUrl, opt_contextProvider, opt_noAutoProtect); + return instance; +}; + + +/** + * Default implementation of XHR sender interface. + * + * @param {string} uri URI to make request to. + * @param {string} method Send method. + * @param {string} content Post data. + * @param {Object|goog.structs.Map=} opt_headers Map of headers to add to the + * request. + */ +goog.debug.ErrorReporter.defaultXhrSender = function(uri, method, content, + opt_headers) { + goog.net.XhrIo.send(uri, null, method, content, opt_headers); +}; + + +/** + * Installs exception protection for an entry point function in addition + * to those that are protected by default. + * Has no effect in IE because window.onerror is used for reporting + * exceptions in that case. + * + * @this {goog.debug.ErrorReporter} + * @param {Function} fn An entry point function to be protected. + * @return {Function} A protected wrapper function that calls the entry point + * function or null if the entry point could not be protected. + */ +goog.debug.ErrorReporter.prototype.protectAdditionalEntryPoint = + goog.debug.ErrorReporter.ALLOW_AUTO_PROTECT ? + function(fn) { + if (this.errorHandler_) { + return this.errorHandler_.protectEntryPoint(fn); + } + return null; + } : + function(fn) { + goog.asserts.fail( + 'Cannot call protectAdditionalEntryPoint while ALLOW_AUTO_PROTECT ' + + 'is false. If ALLOW_AUTO_PROTECT is false, the necessary ' + + 'auto-protect code in compiled/optimized mode is removed.'); + return null; + }; + + +if (goog.debug.ErrorReporter.ALLOW_AUTO_PROTECT) { + /** + * Sets up the error reporter. + * + * @private + */ + goog.debug.ErrorReporter.prototype.setup_ = function() { + if (goog.userAgent.IE && !goog.userAgent.isVersionOrHigher('10')) { + // Use "onerror" because caught exceptions in IE don't provide line + // number. + goog.debug.catchErrors( + goog.bind(this.handleException, this), false, null); + } else { + // "onerror" doesn't work with FF2 or Chrome + this.errorHandler_ = new goog.debug.ErrorHandler( + goog.bind(this.handleException, this)); + + this.errorHandler_.protectWindowSetTimeout(); + this.errorHandler_.protectWindowSetInterval(); + this.errorHandler_.protectWindowRequestAnimationFrame(); + goog.debug.entryPointRegistry.monitorAll(this.errorHandler_); + } + }; +} + + +/** + * Add headers to the logging url. + * @param {Object|goog.structs.Map} loggingHeaders Extra headers to send + * to the logging URL. + */ +goog.debug.ErrorReporter.prototype.setLoggingHeaders = + function(loggingHeaders) { + this.extraHeaders_ = loggingHeaders; +}; + + +/** + * Set the function used to send error reports to the server. + * @param {function(string, string, string, (Object|goog.structs.Map)=)} + * xhrSender If provided, this will be used to send a report to the + * server instead of the default method. The function will be given the URI, + * HTTP method request content, and (optionally) request headers to be + * added. + */ +goog.debug.ErrorReporter.prototype.setXhrSender = function(xhrSender) { + this.xhrSender_ = xhrSender; +}; + + +/** + * Handler for caught exceptions. Sends report to the LoggingServlet and + * notifies any listeners. + * + * @param {Object} e The exception. + * @param {!Object<string, string>=} opt_context Context values to optionally + * include in the error report. + */ +goog.debug.ErrorReporter.prototype.handleException = function(e, + opt_context) { + var error = /** @type {!Error} */ (goog.debug.normalizeErrorObject(e)); + + // Construct the context, possibly from the one provided in the argument, and + // pass it to the context provider if there is one. + var context = opt_context ? goog.object.clone(opt_context) : {}; + if (this.contextProvider_) { + try { + this.contextProvider_(error, context); + } catch (err) { + goog.log.error(goog.debug.ErrorReporter.logger_, + 'Context provider threw an exception: ' + err.message); + } + } + // Truncate message to a reasonable length, since it will be sent in the URL. + // The entire URL length historically needed to be 2,083 or less, so leave + // some room for the rest of the URL. + var message = error.message.substring(0, 1900); + if (!(e instanceof goog.debug.Error) || e.reportErrorToServer) { + this.sendErrorReport(message, error.fileName, error.lineNumber, error.stack, + context); + } + + try { + this.dispatchEvent( + new goog.debug.ErrorReporter.ExceptionEvent(error, context)); + } catch (ex) { + // Swallow exception to avoid infinite recursion. + } +}; + + +/** + * Sends an error report to the logging URL. This will not consult the context + * provider, the report will be sent exactly as specified. + * + * @param {string} message Error description. + * @param {string} fileName URL of the JavaScript file with the error. + * @param {number} line Line number of the error. + * @param {string=} opt_trace Call stack trace of the error. + * @param {!Object<string, string>=} opt_context Context information to include + * in the request. + */ +goog.debug.ErrorReporter.prototype.sendErrorReport = + function(message, fileName, line, opt_trace, opt_context) { + try { + // Create the logging URL. + var requestUrl = goog.uri.utils.appendParams(this.handlerUrl_, + 'script', fileName, 'error', message, 'line', line); + + if (!goog.object.isEmpty(this.additionalArguments_)) { + requestUrl = goog.uri.utils.appendParamsFromMap(requestUrl, + this.additionalArguments_); + } + + var queryMap = {}; + queryMap['trace'] = opt_trace; + + // Copy context into query data map + if (opt_context) { + for (var entry in opt_context) { + queryMap[this.contextPrefix_ + entry] = opt_context[entry]; + } + } + + // Copy query data map into request. + var queryData = goog.uri.utils.buildQueryDataFromMap(queryMap); + + // Truncate if truncationLimit set. + if (goog.isNumber(this.truncationLimit_)) { + queryData = queryData.substring(0, this.truncationLimit_); + } + + // Send the request with the contents of the error. + this.xhrSender_(requestUrl, 'POST', queryData, this.extraHeaders_); + } catch (e) { + var logMessage = goog.string.buildString( + 'Error occurred in sending an error report.\n\n', + 'script:', fileName, '\n', + 'line:', line, '\n', + 'error:', message, '\n', + 'trace:', opt_trace); + goog.log.info(goog.debug.ErrorReporter.logger_, logMessage); + } +}; + + +/** + * @param {string} prefix The prefix to appear prepended to all context + * variables in the error report body. + */ +goog.debug.ErrorReporter.prototype.setContextPrefix = function(prefix) { + this.contextPrefix_ = prefix; +}; + + +/** + * @param {?number} limit Size in bytes to begin truncating POST body. Set to + * null to prevent truncation. The limit must be >= 0. + */ +goog.debug.ErrorReporter.prototype.setTruncationLimit = function(limit) { + goog.asserts.assert(!goog.isNumber(limit) || limit >= 0, + 'Body limit must be valid number >= 0 or null'); + this.truncationLimit_ = limit; +}; + + +/** + * @param {!Object<string,string>} urlArgs Set of key-value pairs to append + * to handlerUrl_ before sending XHR. + */ +goog.debug.ErrorReporter.prototype.setAdditionalArguments = function(urlArgs) { + this.additionalArguments_ = urlArgs; +}; + + +/** @override */ +goog.debug.ErrorReporter.prototype.disposeInternal = function() { + if (goog.debug.ErrorReporter.ALLOW_AUTO_PROTECT) { + goog.dispose(this.errorHandler_); + } + goog.debug.ErrorReporter.base(this, 'disposeInternal'); +};
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/debug/fancywindow.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/debug/fancywindow.js b/externs/GCL/externs/goog/debug/fancywindow.js new file mode 100644 index 0000000..d9aea26 --- /dev/null +++ b/externs/GCL/externs/goog/debug/fancywindow.js @@ -0,0 +1,385 @@ +// Copyright 2006 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Definition of the FancyWindow class. Please minimize + * dependencies this file has on other closure classes as any dependency it + * takes won't be able to use the logging infrastructure. + * + * This is a pretty hacky implementation, aimed at making debugging of large + * applications more manageable. + * + * @see ../demos/debug.html + */ + + +goog.provide('goog.debug.FancyWindow'); + +goog.require('goog.array'); +goog.require('goog.debug.DebugWindow'); +goog.require('goog.debug.LogManager'); +goog.require('goog.debug.Logger'); +goog.require('goog.dom.DomHelper'); +goog.require('goog.dom.TagName'); +goog.require('goog.dom.safe'); +goog.require('goog.html.SafeHtml'); +goog.require('goog.html.SafeStyleSheet'); +goog.require('goog.object'); +goog.require('goog.string'); +goog.require('goog.string.Const'); +goog.require('goog.userAgent'); + + + +// TODO(user): Introduce goog.scope for goog.html.SafeHtml once b/12014412 +// is fixed. +/** + * Provides a Fancy extension to the DebugWindow class. Allows filtering based + * on loggers and levels. + * + * @param {string=} opt_identifier Idenitifier for this logging class. + * @param {string=} opt_prefix Prefix pre-pended to messages. + * @constructor + * @extends {goog.debug.DebugWindow} + */ +goog.debug.FancyWindow = function(opt_identifier, opt_prefix) { + this.readOptionsFromLocalStorage_(); + goog.debug.FancyWindow.base(this, 'constructor', opt_identifier, opt_prefix); + /** @private {goog.dom.DomHelper} */ + this.dh_ = null; +}; +goog.inherits(goog.debug.FancyWindow, goog.debug.DebugWindow); + + +/** + * Constant indicating if we are able to use localStorage to persist filters + * @type {boolean} + */ +goog.debug.FancyWindow.HAS_LOCAL_STORE = (function() { + /** @preserveTry */ + try { + return !!window['localStorage'].getItem; + } catch (e) {} + return false; +})(); + + +/** + * Constant defining the prefix to use when storing log levels + * @type {string} + */ +goog.debug.FancyWindow.LOCAL_STORE_PREFIX = 'fancywindow.sel.'; + + +/** @override */ +goog.debug.FancyWindow.prototype.writeBufferToLog = function() { + this.lastCall = goog.now(); + if (this.hasActiveWindow()) { + var logel = this.dh_.getElement('log'); + + // Work out if scrolling is needed before we add the content + var scroll = + logel.scrollHeight - (logel.scrollTop + logel.offsetHeight) <= 100; + + for (var i = 0; i < this.outputBuffer.length; i++) { + var div = this.dh_.createDom(goog.dom.TagName.DIV, 'logmsg'); + goog.dom.safe.setInnerHtml(div, this.outputBuffer[i]); + logel.appendChild(div); + } + this.outputBuffer.length = 0; + this.resizeStuff_(); + + if (scroll) { + logel.scrollTop = logel.scrollHeight; + } + } +}; + + +/** @override */ +goog.debug.FancyWindow.prototype.writeInitialDocument = function() { + if (!this.hasActiveWindow()) { + return; + } + + var doc = this.win.document; + doc.open(); + goog.dom.safe.documentWrite(doc, this.getHtml_()); + doc.close(); + + (goog.userAgent.IE ? doc.body : this.win).onresize = + goog.bind(this.resizeStuff_, this); + + // Create a dom helper for the logging window + this.dh_ = new goog.dom.DomHelper(doc); + + // Don't use events system to reduce dependencies + this.dh_.getElement('openbutton').onclick = + goog.bind(this.openOptions_, this); + this.dh_.getElement('closebutton').onclick = + goog.bind(this.closeOptions_, this); + this.dh_.getElement('clearbutton').onclick = + goog.bind(this.clear, this); + this.dh_.getElement('exitbutton').onclick = + goog.bind(this.exit_, this); + + this.writeSavedMessages(); +}; + + +/** + * Show the options menu. + * @return {boolean} false. + * @private + */ +goog.debug.FancyWindow.prototype.openOptions_ = function() { + var el = goog.asserts.assert(this.dh_.getElement('optionsarea')); + goog.dom.safe.setInnerHtml(el, goog.html.SafeHtml.EMPTY); + + var loggers = goog.debug.FancyWindow.getLoggers_(); + var dh = this.dh_; + for (var i = 0; i < loggers.length; i++) { + var logger = loggers[i]; + var curlevel = logger.getLevel() ? logger.getLevel().name : 'INHERIT'; + var div = dh.createDom(goog.dom.TagName.DIV, {}, + this.getDropDown_('sel' + logger.getName(), curlevel), + dh.createDom(goog.dom.TagName.SPAN, {}, logger.getName() || '(root)')); + el.appendChild(div); + } + + this.dh_.getElement('options').style.display = 'block'; + return false; +}; + + +/** + * Make a drop down for the log levels. + * @param {string} id Logger id. + * @param {string} selected What log level is currently selected. + * @return {Element} The newly created 'select' DOM element. + * @private + */ +goog.debug.FancyWindow.prototype.getDropDown_ = function(id, selected) { + var dh = this.dh_; + var sel = dh.createDom(goog.dom.TagName.SELECT, {'id': id}); + var levels = goog.debug.Logger.Level.PREDEFINED_LEVELS; + for (var i = 0; i < levels.length; i++) { + var level = levels[i]; + var option = dh.createDom(goog.dom.TagName.OPTION, {}, level.name); + if (selected == level.name) { + option.selected = true; + } + sel.appendChild(option); + } + sel.appendChild(dh.createDom(goog.dom.TagName.OPTION, + {'selected': selected == 'INHERIT'}, 'INHERIT')); + return sel; +}; + + +/** + * Close the options menu. + * @return {boolean} The value false. + * @private + */ +goog.debug.FancyWindow.prototype.closeOptions_ = function() { + this.dh_.getElement('options').style.display = 'none'; + var loggers = goog.debug.FancyWindow.getLoggers_(); + var dh = this.dh_; + for (var i = 0; i < loggers.length; i++) { + var logger = loggers[i]; + var sel = dh.getElement('sel' + logger.getName()); + var level = sel.options[sel.selectedIndex].text; + if (level == 'INHERIT') { + logger.setLevel(null); + } else { + logger.setLevel(goog.debug.Logger.Level.getPredefinedLevel(level)); + } + } + this.writeOptionsToLocalStorage_(); + return false; +}; + + +/** + * Resizes the log elements + * @private + */ +goog.debug.FancyWindow.prototype.resizeStuff_ = function() { + var dh = this.dh_; + var logel = dh.getElement('log'); + var headel = dh.getElement('head'); + logel.style.top = headel.offsetHeight + 'px'; + logel.style.height = (dh.getDocument().body.offsetHeight - + headel.offsetHeight - (goog.userAgent.IE ? 4 : 0)) + 'px'; +}; + + +/** + * Handles the user clicking the exit button, disabled the debug window and + * closes the popup. + * @param {Event} e Event object. + * @private + */ +goog.debug.FancyWindow.prototype.exit_ = function(e) { + this.setEnabled(false); + if (this.win) { + this.win.close(); + } +}; + + +/** @override */ +goog.debug.FancyWindow.prototype.getStyleRules = function() { + var baseRules = goog.debug.FancyWindow.base(this, 'getStyleRules'); + var extraRules = goog.html.SafeStyleSheet.fromConstant(goog.string.Const.from( + 'html,body{height:100%;width:100%;margin:0px;padding:0px;' + + 'background-color:#FFF;overflow:hidden}' + + '*{}' + + '.logmsg{border-bottom:1px solid #CCC;padding:2px;font:90% monospace}' + + '#head{position:absolute;width:100%;font:x-small arial;' + + 'border-bottom:2px solid #999;background-color:#EEE;}' + + '#head p{margin:0px 5px;}' + + '#log{position:absolute;width:100%;background-color:#FFF;}' + + '#options{position:absolute;right:0px;width:50%;height:100%;' + + 'border-left:1px solid #999;background-color:#DDD;display:none;' + + 'padding-left: 5px;font:normal small arial;overflow:auto;}' + + '#openbutton,#closebutton{text-decoration:underline;color:#00F;cursor:' + + 'pointer;position:absolute;top:0px;right:5px;font:x-small arial;}' + + '#clearbutton{text-decoration:underline;color:#00F;cursor:' + + 'pointer;position:absolute;top:0px;right:80px;font:x-small arial;}' + + '#exitbutton{text-decoration:underline;color:#00F;cursor:' + + 'pointer;position:absolute;top:0px;right:50px;font:x-small arial;}' + + 'select{font:x-small arial;margin-right:10px;}' + + 'hr{border:0;height:5px;background-color:#8c8;color:#8c8;}')); + return goog.html.SafeStyleSheet.concat(baseRules, extraRules); +}; + + +/** + * Return the default HTML for the debug window + * @return {!goog.html.SafeHtml} Html. + * @private + */ +goog.debug.FancyWindow.prototype.getHtml_ = function() { + var SafeHtml = goog.html.SafeHtml; + var head = SafeHtml.create('head', {}, SafeHtml.concat( + SafeHtml.create('title', {}, 'Logging: ' + this.identifier), + SafeHtml.createStyle(this.getStyleRules()))); + + var body = SafeHtml.create('body', {}, SafeHtml.concat( + SafeHtml.create('div', + {'id': 'log', 'style': goog.string.Const.from('overflow:auto')}), + SafeHtml.create('div', {'id': 'head'}, SafeHtml.concat( + SafeHtml.create('p', {}, + SafeHtml.create('b', {}, 'Logging: ' + this.identifier)), + SafeHtml.create('p', {}, this.welcomeMessage), + SafeHtml.create('span', {'id': 'clearbutton'}, 'clear'), + SafeHtml.create('span', {'id': 'exitbutton'}, 'exit'), + SafeHtml.create('span', {'id': 'openbutton'}, 'options'))), + SafeHtml.create('div', {'id': 'options'}, SafeHtml.concat( + SafeHtml.create('big', {}, + SafeHtml.create('b', {}, 'Options:')), + SafeHtml.create('div', {'id': 'optionsarea'}), + SafeHtml.create('span', {'id': 'closebutton'}, 'save and close'))))); + + return SafeHtml.create('html', {}, SafeHtml.concat(head, body)); +}; + + +/** + * Write logger levels to localStorage if possible. + * @private + */ +goog.debug.FancyWindow.prototype.writeOptionsToLocalStorage_ = function() { + if (!goog.debug.FancyWindow.HAS_LOCAL_STORE) { + return; + } + var loggers = goog.debug.FancyWindow.getLoggers_(); + var storedKeys = goog.debug.FancyWindow.getStoredKeys_(); + for (var i = 0; i < loggers.length; i++) { + var key = goog.debug.FancyWindow.LOCAL_STORE_PREFIX + loggers[i].getName(); + var level = loggers[i].getLevel(); + if (key in storedKeys) { + if (!level) { + window.localStorage.removeItem(key); + } else if (window.localStorage.getItem(key) != level.name) { + window.localStorage.setItem(key, level.name); + } + } else if (level) { + window.localStorage.setItem(key, level.name); + } + } +}; + + +/** + * Sync logger levels with any values stored in localStorage. + * @private + */ +goog.debug.FancyWindow.prototype.readOptionsFromLocalStorage_ = function() { + if (!goog.debug.FancyWindow.HAS_LOCAL_STORE) { + return; + } + var storedKeys = goog.debug.FancyWindow.getStoredKeys_(); + for (var key in storedKeys) { + var loggerName = key.replace(goog.debug.FancyWindow.LOCAL_STORE_PREFIX, ''); + var logger = goog.debug.LogManager.getLogger(loggerName); + var curLevel = logger.getLevel(); + var storedLevel = window.localStorage.getItem(key).toString(); + if (!curLevel || curLevel.toString() != storedLevel) { + logger.setLevel(goog.debug.Logger.Level.getPredefinedLevel(storedLevel)); + } + } +}; + + +/** + * Helper function to create a list of locally stored keys. Used to avoid + * expensive localStorage.getItem() calls. + * @return {!Object} List of keys. + * @private + */ +goog.debug.FancyWindow.getStoredKeys_ = function() { + var storedKeys = {}; + for (var i = 0, len = window.localStorage.length; i < len; i++) { + var key = window.localStorage.key(i); + if (key != null && goog.string.startsWith( + key, goog.debug.FancyWindow.LOCAL_STORE_PREFIX)) { + storedKeys[key] = true; + } + } + return storedKeys; +}; + + +/** + * Gets a sorted array of all the loggers registered. + * @return {!Array<!goog.debug.Logger>} Array of logger instances. + * @private + */ +goog.debug.FancyWindow.getLoggers_ = function() { + var loggers = goog.object.getValues(goog.debug.LogManager.getLoggers()); + + /** + * @param {!goog.debug.Logger} a + * @param {!goog.debug.Logger} b + * @return {number} + */ + var loggerSort = function(a, b) { + return goog.array.defaultCompare(a.getName(), b.getName()); + }; + goog.array.sort(loggers, loggerSort); + return loggers; +}; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/debug/formatter.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/debug/formatter.js b/externs/GCL/externs/goog/debug/formatter.js new file mode 100644 index 0000000..949a652 --- /dev/null +++ b/externs/GCL/externs/goog/debug/formatter.js @@ -0,0 +1,387 @@ +// Copyright 2006 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Definition of various formatters for logging. Please minimize + * dependencies this file has on other closure classes as any dependency it + * takes won't be able to use the logging infrastructure. + * + */ + +goog.provide('goog.debug.Formatter'); +goog.provide('goog.debug.HtmlFormatter'); +goog.provide('goog.debug.TextFormatter'); + +goog.require('goog.debug'); +goog.require('goog.debug.Logger'); +goog.require('goog.debug.RelativeTimeProvider'); +goog.require('goog.html.SafeHtml'); + + + +/** + * Base class for Formatters. A Formatter is used to format a LogRecord into + * something that can be displayed to the user. + * + * @param {string=} opt_prefix The prefix to place before text records. + * @constructor + */ +goog.debug.Formatter = function(opt_prefix) { + this.prefix_ = opt_prefix || ''; + + /** + * A provider that returns the relative start time. + * @type {goog.debug.RelativeTimeProvider} + * @private + */ + this.startTimeProvider_ = + goog.debug.RelativeTimeProvider.getDefaultInstance(); +}; + + +/** + * Whether to append newlines to the end of formatted log records. + * @type {boolean} + */ +goog.debug.Formatter.prototype.appendNewline = true; + + +/** + * Whether to show absolute time in the DebugWindow. + * @type {boolean} + */ +goog.debug.Formatter.prototype.showAbsoluteTime = true; + + +/** + * Whether to show relative time in the DebugWindow. + * @type {boolean} + */ +goog.debug.Formatter.prototype.showRelativeTime = true; + + +/** + * Whether to show the logger name in the DebugWindow. + * @type {boolean} + */ +goog.debug.Formatter.prototype.showLoggerName = true; + + +/** + * Whether to show the logger exception text. + * @type {boolean} + */ +goog.debug.Formatter.prototype.showExceptionText = false; + + +/** + * Whether to show the severity level. + * @type {boolean} + */ +goog.debug.Formatter.prototype.showSeverityLevel = false; + + +/** + * Formats a record. + * @param {goog.debug.LogRecord} logRecord the logRecord to format. + * @return {string} The formatted string. + */ +goog.debug.Formatter.prototype.formatRecord = goog.abstractMethod; + + +/** + * Formats a record as SafeHtml. + * @param {goog.debug.LogRecord} logRecord the logRecord to format. + * @return {!goog.html.SafeHtml} The formatted string as SafeHtml. + */ +goog.debug.Formatter.prototype.formatRecordAsHtml = goog.abstractMethod; + + +/** + * Sets the start time provider. By default, this is the default instance + * but can be changed. + * @param {goog.debug.RelativeTimeProvider} provider The provider to use. + */ +goog.debug.Formatter.prototype.setStartTimeProvider = function(provider) { + this.startTimeProvider_ = provider; +}; + + +/** + * Returns the start time provider. By default, this is the default instance + * but can be changed. + * @return {goog.debug.RelativeTimeProvider} The start time provider. + */ +goog.debug.Formatter.prototype.getStartTimeProvider = function() { + return this.startTimeProvider_; +}; + + +/** + * Resets the start relative time. + */ +goog.debug.Formatter.prototype.resetRelativeTimeStart = function() { + this.startTimeProvider_.reset(); +}; + + +/** + * Returns a string for the time/date of the LogRecord. + * @param {goog.debug.LogRecord} logRecord The record to get a time stamp for. + * @return {string} A string representation of the time/date of the LogRecord. + * @private + */ +goog.debug.Formatter.getDateTimeStamp_ = function(logRecord) { + var time = new Date(logRecord.getMillis()); + return goog.debug.Formatter.getTwoDigitString_((time.getFullYear() - 2000)) + + goog.debug.Formatter.getTwoDigitString_((time.getMonth() + 1)) + + goog.debug.Formatter.getTwoDigitString_(time.getDate()) + ' ' + + goog.debug.Formatter.getTwoDigitString_(time.getHours()) + ':' + + goog.debug.Formatter.getTwoDigitString_(time.getMinutes()) + ':' + + goog.debug.Formatter.getTwoDigitString_(time.getSeconds()) + '.' + + goog.debug.Formatter.getTwoDigitString_( + Math.floor(time.getMilliseconds() / 10)); +}; + + +/** + * Returns the number as a two-digit string, meaning it prepends a 0 if the + * number if less than 10. + * @param {number} n The number to format. + * @return {string} A two-digit string representation of {@code n}. + * @private + */ +goog.debug.Formatter.getTwoDigitString_ = function(n) { + if (n < 10) { + return '0' + n; + } + return String(n); +}; + + +/** + * Returns a string for the number of seconds relative to the start time. + * Prepads with spaces so that anything less than 1000 seconds takes up the + * same number of characters for better formatting. + * @param {goog.debug.LogRecord} logRecord The log to compare time to. + * @param {number} relativeTimeStart The start time to compare to. + * @return {string} The number of seconds of the LogRecord relative to the + * start time. + * @private + */ +goog.debug.Formatter.getRelativeTime_ = function(logRecord, + relativeTimeStart) { + var ms = logRecord.getMillis() - relativeTimeStart; + var sec = ms / 1000; + var str = sec.toFixed(3); + + var spacesToPrepend = 0; + if (sec < 1) { + spacesToPrepend = 2; + } else { + while (sec < 100) { + spacesToPrepend++; + sec *= 10; + } + } + while (spacesToPrepend-- > 0) { + str = ' ' + str; + } + return str; +}; + + + +/** + * Formatter that returns formatted html. See formatRecord for the classes + * it uses for various types of formatted output. + * + * @param {string=} opt_prefix The prefix to place before text records. + * @constructor + * @extends {goog.debug.Formatter} + */ +goog.debug.HtmlFormatter = function(opt_prefix) { + goog.debug.Formatter.call(this, opt_prefix); +}; +goog.inherits(goog.debug.HtmlFormatter, goog.debug.Formatter); + + +/** + * Whether to show the logger exception text + * @type {boolean} + * @override + */ +goog.debug.HtmlFormatter.prototype.showExceptionText = true; + + +/** + * Formats a record + * @param {goog.debug.LogRecord} logRecord the logRecord to format. + * @return {string} The formatted string as html. + * @override + */ +goog.debug.HtmlFormatter.prototype.formatRecord = function(logRecord) { + if (!logRecord) { + return ''; + } + // OK not to use goog.html.SafeHtml.unwrap() here. + return this.formatRecordAsHtml(logRecord).getTypedStringValue(); +}; + + +/** + * Formats a record. + * @param {goog.debug.LogRecord} logRecord the logRecord to format. + * @return {!goog.html.SafeHtml} The formatted string as SafeHtml. + * @override + */ +goog.debug.HtmlFormatter.prototype.formatRecordAsHtml = function(logRecord) { + if (!logRecord) { + return goog.html.SafeHtml.EMPTY; + } + + var className; + switch (logRecord.getLevel().value) { + case goog.debug.Logger.Level.SHOUT.value: + className = 'dbg-sh'; + break; + case goog.debug.Logger.Level.SEVERE.value: + className = 'dbg-sev'; + break; + case goog.debug.Logger.Level.WARNING.value: + className = 'dbg-w'; + break; + case goog.debug.Logger.Level.INFO.value: + className = 'dbg-i'; + break; + case goog.debug.Logger.Level.FINE.value: + default: + className = 'dbg-f'; + break; + } + + // HTML for user defined prefix, time, logger name, and severity. + var sb = []; + sb.push(this.prefix_, ' '); + if (this.showAbsoluteTime) { + sb.push('[', goog.debug.Formatter.getDateTimeStamp_(logRecord), '] '); + } + if (this.showRelativeTime) { + sb.push('[', + goog.debug.Formatter.getRelativeTime_( + logRecord, this.startTimeProvider_.get()), + 's] '); + } + if (this.showLoggerName) { + sb.push('[', logRecord.getLoggerName(), '] '); + } + if (this.showSeverityLevel) { + sb.push('[', logRecord.getLevel().name, '] '); + } + var fullPrefixHtml = + goog.html.SafeHtml.htmlEscapePreservingNewlinesAndSpaces(sb.join('')); + + // HTML for exception text and log record. + var exceptionHtml = goog.html.SafeHtml.EMPTY; + if (this.showExceptionText && logRecord.getException()) { + exceptionHtml = goog.html.SafeHtml.concat( + goog.html.SafeHtml.create('br'), + goog.debug.exposeExceptionAsHtml(logRecord.getException())); + } + var logRecordHtml = goog.html.SafeHtml.htmlEscapePreservingNewlinesAndSpaces( + logRecord.getMessage()); + var recordAndExceptionHtml = goog.html.SafeHtml.create( + 'span', + {'class': className}, + goog.html.SafeHtml.concat(logRecordHtml, exceptionHtml)); + + + // Combine both pieces of HTML and, if needed, append a final newline. + var html; + if (this.appendNewline) { + html = goog.html.SafeHtml.concat(fullPrefixHtml, recordAndExceptionHtml, + goog.html.SafeHtml.create('br')); + } else { + html = goog.html.SafeHtml.concat(fullPrefixHtml, recordAndExceptionHtml); + } + return html; +}; + + + +/** + * Formatter that returns formatted plain text + * + * @param {string=} opt_prefix The prefix to place before text records. + * @constructor + * @extends {goog.debug.Formatter} + * @final + */ +goog.debug.TextFormatter = function(opt_prefix) { + goog.debug.Formatter.call(this, opt_prefix); +}; +goog.inherits(goog.debug.TextFormatter, goog.debug.Formatter); + + +/** + * Formats a record as text + * @param {goog.debug.LogRecord} logRecord the logRecord to format. + * @return {string} The formatted string. + * @override + */ +goog.debug.TextFormatter.prototype.formatRecord = function(logRecord) { + var sb = []; + sb.push(this.prefix_, ' '); + if (this.showAbsoluteTime) { + sb.push('[', goog.debug.Formatter.getDateTimeStamp_(logRecord), '] '); + } + if (this.showRelativeTime) { + sb.push('[', goog.debug.Formatter.getRelativeTime_(logRecord, + this.startTimeProvider_.get()), 's] '); + } + + if (this.showLoggerName) { + sb.push('[', logRecord.getLoggerName(), '] '); + } + if (this.showSeverityLevel) { + sb.push('[', logRecord.getLevel().name, '] '); + } + sb.push(logRecord.getMessage()); + if (this.showExceptionText) { + var exception = logRecord.getException(); + if (exception) { + var exceptionText = exception instanceof Error ? + exception.message : + exception.toString(); + sb.push('\n', exceptionText); + } + } + if (this.appendNewline) { + sb.push('\n'); + } + return sb.join(''); +}; + + +/** + * Formats a record as text + * @param {goog.debug.LogRecord} logRecord the logRecord to format. + * @return {!goog.html.SafeHtml} The formatted string as SafeHtml. This is + * just an HTML-escaped version of the text obtained from formatRecord(). + * @override + */ +goog.debug.TextFormatter.prototype.formatRecordAsHtml = function(logRecord) { + return goog.html.SafeHtml.htmlEscapePreservingNewlinesAndSpaces( + goog.debug.TextFormatter.prototype.formatRecord(logRecord)); +}; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/debug/fpsdisplay.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/debug/fpsdisplay.js b/externs/GCL/externs/goog/debug/fpsdisplay.js new file mode 100644 index 0000000..f8f525f --- /dev/null +++ b/externs/GCL/externs/goog/debug/fpsdisplay.js @@ -0,0 +1,165 @@ +// Copyright 2011 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Displays frames per second (FPS) for the current window. + * Only supported in browsers that support requestAnimationFrame. + * See: https://developer.mozilla.org/en/DOM/window.requestAnimationFrame. + * + * @see ../demos/fpsdisplay.html + */ + +goog.provide('goog.debug.FpsDisplay'); + +goog.require('goog.asserts'); +goog.require('goog.async.AnimationDelay'); +goog.require('goog.dom'); +goog.require('goog.dom.TagName'); +goog.require('goog.ui.Component'); + + + +/** + * Displays frames per seconds that the window this component is + * rendered in is animating at. + * + * @param {goog.dom.DomHelper=} opt_domHelper An optional dom helper. + * @constructor + * @extends {goog.ui.Component} + * @final + */ +goog.debug.FpsDisplay = function(opt_domHelper) { + goog.debug.FpsDisplay.base(this, 'constructor', opt_domHelper); +}; +goog.inherits(goog.debug.FpsDisplay, goog.ui.Component); + + +/** + * CSS class for the FPS display. + */ +goog.debug.FpsDisplay.CSS = goog.getCssName('goog-fps-display'); + + +/** + * The number of samples per FPS report. + */ +goog.debug.FpsDisplay.SAMPLES = 10; + + +/** + * The current animation. + * @type {goog.debug.FpsDisplay.FpsAnimation_} + * @private + */ +goog.debug.FpsDisplay.prototype.animation_ = null; + + +/** @override */ +goog.debug.FpsDisplay.prototype.createDom = function() { + this.setElementInternal(this.getDomHelper().createDom( + goog.dom.TagName.DIV, goog.debug.FpsDisplay.CSS)); +}; + + +/** @override */ +goog.debug.FpsDisplay.prototype.enterDocument = function() { + goog.debug.FpsDisplay.base(this, 'enterDocument'); + this.animation_ = new goog.debug.FpsDisplay.FpsAnimation_(this.getElement()); + this.delay_ = new goog.async.AnimationDelay( + this.handleDelay_, this.getDomHelper().getWindow(), this); + this.delay_.start(); +}; + + +/** + * @param {number} now The current time. + * @private + */ +goog.debug.FpsDisplay.prototype.handleDelay_ = function(now) { + if (this.isInDocument()) { + this.animation_.onAnimationFrame(now); + this.delay_.start(); + } +}; + + +/** @override */ +goog.debug.FpsDisplay.prototype.exitDocument = function() { + goog.debug.FpsDisplay.base(this, 'exitDocument'); + this.animation_ = null; + goog.dispose(this.delay_); +}; + + +/** + * @return {number} The average frames per second. + */ +goog.debug.FpsDisplay.prototype.getFps = function() { + goog.asserts.assert( + this.isInDocument(), 'Render the FPS display before querying FPS'); + return this.animation_.lastFps_; +}; + + + +/** + * @param {Element} elem An element to hold the FPS count. + * @constructor + * @private + */ +goog.debug.FpsDisplay.FpsAnimation_ = function(elem) { + /** + * An element to hold the current FPS rate. + * @type {Element} + * @private + */ + this.element_ = elem; + + /** + * The number of frames observed so far. + * @type {number} + * @private + */ + this.frameNumber_ = 0; +}; + + +/** + * The last time which we reported FPS at. + * @type {number} + * @private + */ +goog.debug.FpsDisplay.FpsAnimation_.prototype.lastTime_ = 0; + + +/** + * The last average FPS. + * @type {number} + * @private + */ +goog.debug.FpsDisplay.FpsAnimation_.prototype.lastFps_ = -1; + + +/** + * @param {number} now The current time. + */ +goog.debug.FpsDisplay.FpsAnimation_.prototype.onAnimationFrame = function(now) { + var SAMPLES = goog.debug.FpsDisplay.SAMPLES; + if (this.frameNumber_ % SAMPLES == 0) { + this.lastFps_ = Math.round((1000 * SAMPLES) / (now - this.lastTime_)); + goog.dom.setTextContent(this.element_, this.lastFps_); + this.lastTime_ = now; + } + this.frameNumber_++; +}; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/debug/gcdiagnostics.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/debug/gcdiagnostics.js b/externs/GCL/externs/goog/debug/gcdiagnostics.js new file mode 100644 index 0000000..5e5ba9a --- /dev/null +++ b/externs/GCL/externs/goog/debug/gcdiagnostics.js @@ -0,0 +1,143 @@ +// Copyright 2007 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Definition of the GcDiagnostics class. + * + */ + +goog.provide('goog.debug.GcDiagnostics'); + +goog.require('goog.debug.Trace'); +goog.require('goog.log'); +goog.require('goog.userAgent'); + + + +/** + * Class used for singleton goog.debug.GcDiagnostics. Used to hook into + * the L2 ActiveX controller to profile garbage collection information in IE. + * Can be used in combination with tracers (goog.debug.Trace), to provide object + * allocation counts from within the tracers or used alone by invoking start and + * stop. + * + * See http://go/l2binary for the install. + * TODO(user): Move the L2 installer somewhere more general. + * @constructor + * @private + */ +goog.debug.GcDiagnostics_ = function() {}; + + +/** + * Install the GcDiagnostics tool. + */ +goog.debug.GcDiagnostics_.prototype.install = function() { + if (goog.userAgent.IE) { + /** @preserveTry */ + try { + var l2Helper = new ActiveXObject('L2.NativeHelper'); + + // If using tracers, use the higher precision timer provided by L2. + if (goog.debug.Trace_) { + goog.debug.Trace_.now = function() { + return l2Helper['getMilliSeconds'](); + }; + } + + if (l2Helper['gcTracer']) { + l2Helper['gcTracer']['installGcTracing'](); + this.gcTracer_ = l2Helper['gcTracer']; + if (goog.debug.Trace) { + // If tracers are in use, register the gcTracer so that per tracer + // allocations are recorded. + goog.debug.Trace.setGcTracer(this.gcTracer_); + } + } + goog.log.info(this.logger_, 'Installed L2 native helper'); + } catch (e) { + goog.log.info(this.logger_, 'Failed to install L2 native helper: ' + e); + } + } +}; + + +/** + * Logger for the gcDiagnotics + * @type {goog.log.Logger} + * @private + */ +goog.debug.GcDiagnostics_.prototype.logger_ = + goog.log.getLogger('goog.debug.GcDiagnostics'); + + +/** + * Starts recording garbage collection information. If a trace is already in + * progress, it is ended. + */ +goog.debug.GcDiagnostics_.prototype.start = function() { + if (this.gcTracer_) { + if (this.gcTracer_['isTracing']()) { + this.gcTracer_['endGcTracing'](); + } + this.gcTracer_['startGcTracing'](); + } +}; + + +/** + * Stops recording garbage collection information. Logs details on the garbage + * collections that occurred between start and stop. If tracers are in use, + * adds comments where each GC occurs. + */ +goog.debug.GcDiagnostics_.prototype.stop = function() { + if (this.gcTracer_ && this.gcTracer_['isTracing']()) { + var gcTracer = this.gcTracer_; + this.gcTracer_['endGcTracing'](); + + var numGCs = gcTracer['getNumTraces'](); + goog.log.info(this.logger_, '*********GC TRACE*********'); + goog.log.info(this.logger_, 'GC ran ' + numGCs + ' times.'); + var totalTime = 0; + for (var i = 0; i < numGCs; i++) { + var trace = gcTracer['getTrace'](i); + + var msStart = trace['gcStartTime']; + var msElapsed = trace['gcElapsedTime']; + + var msRounded = Math.round(msElapsed * 10) / 10; + var s = 'GC ' + i + ': ' + msRounded + ' ms, ' + + 'numVValAlloc=' + trace['numVValAlloc'] + ', ' + + 'numVarAlloc=' + trace['numVarAlloc'] + ', ' + + 'numBytesSysAlloc=' + trace['numBytesSysAlloc']; + if (goog.debug.Trace) { + goog.debug.Trace.addComment(s, null, msStart); + } + goog.log.info(this.logger_, s); + totalTime += msElapsed; + } + if (goog.debug.Trace) { + goog.debug.Trace.addComment('Total GC time was ' + totalTime + ' ms.'); + } + goog.log.info(this.logger_, 'Total GC time was ' + totalTime + ' ms.'); + goog.log.info(this.logger_, '*********GC TRACE*********'); + } +}; + + +/** + * Singleton GcDiagnostics object + * @type {goog.debug.GcDiagnostics_} + */ +goog.debug.GcDiagnostics = new goog.debug.GcDiagnostics_(); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/debug/logbuffer.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/debug/logbuffer.js b/externs/GCL/externs/goog/debug/logbuffer.js new file mode 100644 index 0000000..7e3de4b --- /dev/null +++ b/externs/GCL/externs/goog/debug/logbuffer.js @@ -0,0 +1,148 @@ +// Copyright 2010 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview A buffer for log records. The purpose of this is to improve + * logging performance by re-using old objects when the buffer becomes full and + * to eliminate the need for each app to implement their own log buffer. The + * disadvantage to doing this is that log handlers cannot maintain references to + * log records and expect that they are not overwriten at a later point. + * + * @author [email protected] (Andrew Grieve) + */ + +goog.provide('goog.debug.LogBuffer'); + +goog.require('goog.asserts'); +goog.require('goog.debug.LogRecord'); + + + +/** + * Creates the log buffer. + * @constructor + * @final + */ +goog.debug.LogBuffer = function() { + goog.asserts.assert(goog.debug.LogBuffer.isBufferingEnabled(), + 'Cannot use goog.debug.LogBuffer without defining ' + + 'goog.debug.LogBuffer.CAPACITY.'); + this.clear(); +}; + + +/** + * A static method that always returns the same instance of LogBuffer. + * @return {!goog.debug.LogBuffer} The LogBuffer singleton instance. + */ +goog.debug.LogBuffer.getInstance = function() { + if (!goog.debug.LogBuffer.instance_) { + // This function is written with the return statement after the assignment + // to avoid the jscompiler StripCode bug described in http://b/2608064. + // After that bug is fixed this can be refactored. + goog.debug.LogBuffer.instance_ = new goog.debug.LogBuffer(); + } + return goog.debug.LogBuffer.instance_; +}; + + +/** + * @define {number} The number of log records to buffer. 0 means disable + * buffering. + */ +goog.define('goog.debug.LogBuffer.CAPACITY', 0); + + +/** + * The array to store the records. + * @type {!Array<!goog.debug.LogRecord|undefined>} + * @private + */ +goog.debug.LogBuffer.prototype.buffer_; + + +/** + * The index of the most recently added record or -1 if there are no records. + * @type {number} + * @private + */ +goog.debug.LogBuffer.prototype.curIndex_; + + +/** + * Whether the buffer is at capacity. + * @type {boolean} + * @private + */ +goog.debug.LogBuffer.prototype.isFull_; + + +/** + * Adds a log record to the buffer, possibly overwriting the oldest record. + * @param {goog.debug.Logger.Level} level One of the level identifiers. + * @param {string} msg The string message. + * @param {string} loggerName The name of the source logger. + * @return {!goog.debug.LogRecord} The log record. + */ +goog.debug.LogBuffer.prototype.addRecord = function(level, msg, loggerName) { + var curIndex = (this.curIndex_ + 1) % goog.debug.LogBuffer.CAPACITY; + this.curIndex_ = curIndex; + if (this.isFull_) { + var ret = this.buffer_[curIndex]; + ret.reset(level, msg, loggerName); + return ret; + } + this.isFull_ = curIndex == goog.debug.LogBuffer.CAPACITY - 1; + return this.buffer_[curIndex] = + new goog.debug.LogRecord(level, msg, loggerName); +}; + + +/** + * @return {boolean} Whether the log buffer is enabled. + */ +goog.debug.LogBuffer.isBufferingEnabled = function() { + return goog.debug.LogBuffer.CAPACITY > 0; +}; + + +/** + * Removes all buffered log records. + */ +goog.debug.LogBuffer.prototype.clear = function() { + this.buffer_ = new Array(goog.debug.LogBuffer.CAPACITY); + this.curIndex_ = -1; + this.isFull_ = false; +}; + + +/** + * Calls the given function for each buffered log record, starting with the + * oldest one. + * @param {function(!goog.debug.LogRecord)} func The function to call. + */ +goog.debug.LogBuffer.prototype.forEachRecord = function(func) { + var buffer = this.buffer_; + // Corner case: no records. + if (!buffer[0]) { + return; + } + var curIndex = this.curIndex_; + var i = this.isFull_ ? curIndex : -1; + do { + i = (i + 1) % goog.debug.LogBuffer.CAPACITY; + func(/** @type {!goog.debug.LogRecord} */ (buffer[i])); + } while (i != curIndex); +}; + http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/debug/logger.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/debug/logger.js b/externs/GCL/externs/goog/debug/logger.js new file mode 100644 index 0000000..5ced90a --- /dev/null +++ b/externs/GCL/externs/goog/debug/logger.js @@ -0,0 +1,873 @@ +// Copyright 2006 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Definition of the Logger class. Please minimize dependencies + * this file has on other closure classes as any dependency it takes won't be + * able to use the logging infrastructure. + * + * @see ../demos/debug.html + */ + +goog.provide('goog.debug.LogManager'); +goog.provide('goog.debug.Loggable'); +goog.provide('goog.debug.Logger'); +goog.provide('goog.debug.Logger.Level'); + +goog.require('goog.array'); +goog.require('goog.asserts'); +goog.require('goog.debug'); +goog.require('goog.debug.LogBuffer'); +goog.require('goog.debug.LogRecord'); + + +/** + * A message value that can be handled by a Logger. + * + * Functions are treated like callbacks, but are only called when the event's + * log level is enabled. This is useful for logging messages that are expensive + * to construct. + * + * @typedef {string|function(): string} + */ +goog.debug.Loggable; + + + +/** + * The Logger is an object used for logging debug messages. Loggers are + * normally named, using a hierarchical dot-separated namespace. Logger names + * can be arbitrary strings, but they should normally be based on the package + * name or class name of the logged component, such as goog.net.BrowserChannel. + * + * The Logger object is loosely based on the java class + * java.util.logging.Logger. It supports different levels of filtering for + * different loggers. + * + * The logger object should never be instantiated by application code. It + * should always use the goog.debug.Logger.getLogger function. + * + * @constructor + * @param {string} name The name of the Logger. + * @final + */ +goog.debug.Logger = function(name) { + /** + * Name of the Logger. Generally a dot-separated namespace + * @private {string} + */ + this.name_ = name; + + /** + * Parent Logger. + * @private {goog.debug.Logger} + */ + this.parent_ = null; + + /** + * Level that this logger only filters above. Null indicates it should + * inherit from the parent. + * @private {goog.debug.Logger.Level} + */ + this.level_ = null; + + /** + * Map of children loggers. The keys are the leaf names of the children and + * the values are the child loggers. + * @private {Object} + */ + this.children_ = null; + + /** + * Handlers that are listening to this logger. + * @private {Array<Function>} + */ + this.handlers_ = null; +}; + + +/** @const */ +goog.debug.Logger.ROOT_LOGGER_NAME = ''; + + +/** + * @define {boolean} Toggles whether loggers other than the root logger can have + * log handlers attached to them and whether they can have their log level + * set. Logging is a bit faster when this is set to false. + */ +goog.define('goog.debug.Logger.ENABLE_HIERARCHY', true); + + +if (!goog.debug.Logger.ENABLE_HIERARCHY) { + /** + * @type {!Array<Function>} + * @private + */ + goog.debug.Logger.rootHandlers_ = []; + + + /** + * @type {goog.debug.Logger.Level} + * @private + */ + goog.debug.Logger.rootLevel_; +} + + + +/** + * The Level class defines a set of standard logging levels that + * can be used to control logging output. The logging Level objects + * are ordered and are specified by ordered integers. Enabling logging + * at a given level also enables logging at all higher levels. + * <p> + * Clients should normally use the predefined Level constants such + * as Level.SEVERE. + * <p> + * The levels in descending order are: + * <ul> + * <li>SEVERE (highest value) + * <li>WARNING + * <li>INFO + * <li>CONFIG + * <li>FINE + * <li>FINER + * <li>FINEST (lowest value) + * </ul> + * In addition there is a level OFF that can be used to turn + * off logging, and a level ALL that can be used to enable + * logging of all messages. + * + * @param {string} name The name of the level. + * @param {number} value The numeric value of the level. + * @constructor + * @final + */ +goog.debug.Logger.Level = function(name, value) { + /** + * The name of the level + * @type {string} + */ + this.name = name; + + /** + * The numeric value of the level + * @type {number} + */ + this.value = value; +}; + + +/** + * @return {string} String representation of the logger level. + * @override + */ +goog.debug.Logger.Level.prototype.toString = function() { + return this.name; +}; + + +/** + * OFF is a special level that can be used to turn off logging. + * This level is initialized to <CODE>Infinity</CODE>. + * @type {!goog.debug.Logger.Level} + */ +goog.debug.Logger.Level.OFF = + new goog.debug.Logger.Level('OFF', Infinity); + + +/** + * SHOUT is a message level for extra debugging loudness. + * This level is initialized to <CODE>1200</CODE>. + * @type {!goog.debug.Logger.Level} + */ +goog.debug.Logger.Level.SHOUT = new goog.debug.Logger.Level('SHOUT', 1200); + + +/** + * SEVERE is a message level indicating a serious failure. + * This level is initialized to <CODE>1000</CODE>. + * @type {!goog.debug.Logger.Level} + */ +goog.debug.Logger.Level.SEVERE = new goog.debug.Logger.Level('SEVERE', 1000); + + +/** + * WARNING is a message level indicating a potential problem. + * This level is initialized to <CODE>900</CODE>. + * @type {!goog.debug.Logger.Level} + */ +goog.debug.Logger.Level.WARNING = new goog.debug.Logger.Level('WARNING', 900); + + +/** + * INFO is a message level for informational messages. + * This level is initialized to <CODE>800</CODE>. + * @type {!goog.debug.Logger.Level} + */ +goog.debug.Logger.Level.INFO = new goog.debug.Logger.Level('INFO', 800); + + +/** + * CONFIG is a message level for static configuration messages. + * This level is initialized to <CODE>700</CODE>. + * @type {!goog.debug.Logger.Level} + */ +goog.debug.Logger.Level.CONFIG = new goog.debug.Logger.Level('CONFIG', 700); + + +/** + * FINE is a message level providing tracing information. + * This level is initialized to <CODE>500</CODE>. + * @type {!goog.debug.Logger.Level} + */ +goog.debug.Logger.Level.FINE = new goog.debug.Logger.Level('FINE', 500); + + +/** + * FINER indicates a fairly detailed tracing message. + * This level is initialized to <CODE>400</CODE>. + * @type {!goog.debug.Logger.Level} + */ +goog.debug.Logger.Level.FINER = new goog.debug.Logger.Level('FINER', 400); + +/** + * FINEST indicates a highly detailed tracing message. + * This level is initialized to <CODE>300</CODE>. + * @type {!goog.debug.Logger.Level} + */ + +goog.debug.Logger.Level.FINEST = new goog.debug.Logger.Level('FINEST', 300); + + +/** + * ALL indicates that all messages should be logged. + * This level is initialized to <CODE>0</CODE>. + * @type {!goog.debug.Logger.Level} + */ +goog.debug.Logger.Level.ALL = new goog.debug.Logger.Level('ALL', 0); + + +/** + * The predefined levels. + * @type {!Array<!goog.debug.Logger.Level>} + * @final + */ +goog.debug.Logger.Level.PREDEFINED_LEVELS = [ + goog.debug.Logger.Level.OFF, + goog.debug.Logger.Level.SHOUT, + goog.debug.Logger.Level.SEVERE, + goog.debug.Logger.Level.WARNING, + goog.debug.Logger.Level.INFO, + goog.debug.Logger.Level.CONFIG, + goog.debug.Logger.Level.FINE, + goog.debug.Logger.Level.FINER, + goog.debug.Logger.Level.FINEST, + goog.debug.Logger.Level.ALL]; + + +/** + * A lookup map used to find the level object based on the name or value of + * the level object. + * @type {Object} + * @private + */ +goog.debug.Logger.Level.predefinedLevelsCache_ = null; + + +/** + * Creates the predefined levels cache and populates it. + * @private + */ +goog.debug.Logger.Level.createPredefinedLevelsCache_ = function() { + goog.debug.Logger.Level.predefinedLevelsCache_ = {}; + for (var i = 0, level; level = goog.debug.Logger.Level.PREDEFINED_LEVELS[i]; + i++) { + goog.debug.Logger.Level.predefinedLevelsCache_[level.value] = level; + goog.debug.Logger.Level.predefinedLevelsCache_[level.name] = level; + } +}; + + +/** + * Gets the predefined level with the given name. + * @param {string} name The name of the level. + * @return {goog.debug.Logger.Level} The level, or null if none found. + */ +goog.debug.Logger.Level.getPredefinedLevel = function(name) { + if (!goog.debug.Logger.Level.predefinedLevelsCache_) { + goog.debug.Logger.Level.createPredefinedLevelsCache_(); + } + + return goog.debug.Logger.Level.predefinedLevelsCache_[name] || null; +}; + + +/** + * Gets the highest predefined level <= #value. + * @param {number} value Level value. + * @return {goog.debug.Logger.Level} The level, or null if none found. + */ +goog.debug.Logger.Level.getPredefinedLevelByValue = function(value) { + if (!goog.debug.Logger.Level.predefinedLevelsCache_) { + goog.debug.Logger.Level.createPredefinedLevelsCache_(); + } + + if (value in goog.debug.Logger.Level.predefinedLevelsCache_) { + return goog.debug.Logger.Level.predefinedLevelsCache_[value]; + } + + for (var i = 0; i < goog.debug.Logger.Level.PREDEFINED_LEVELS.length; ++i) { + var level = goog.debug.Logger.Level.PREDEFINED_LEVELS[i]; + if (level.value <= value) { + return level; + } + } + return null; +}; + + +/** + * Finds or creates a logger for a named subsystem. If a logger has already been + * created with the given name it is returned. Otherwise a new logger is + * created. If a new logger is created its log level will be configured based + * on the LogManager configuration and it will configured to also send logging + * output to its parent's handlers. It will be registered in the LogManager + * global namespace. + * + * @param {string} name A name for the logger. This should be a dot-separated + * name and should normally be based on the package name or class name of the + * subsystem, such as goog.net.BrowserChannel. + * @return {!goog.debug.Logger} The named logger. + * @deprecated use goog.log instead. http://go/goog-debug-logger-deprecated + */ +goog.debug.Logger.getLogger = function(name) { + return goog.debug.LogManager.getLogger(name); +}; + + +/** + * Logs a message to profiling tools, if available. + * {@see https://developers.google.com/web-toolkit/speedtracer/logging-api} + * {@see http://msdn.microsoft.com/en-us/library/dd433074(VS.85).aspx} + * @param {string} msg The message to log. + */ +goog.debug.Logger.logToProfilers = function(msg) { + // Using goog.global, as loggers might be used in window-less contexts. + if (goog.global['console']) { + if (goog.global['console']['timeStamp']) { + // Logs a message to Firebug, Web Inspector, SpeedTracer, etc. + goog.global['console']['timeStamp'](msg); + } else if (goog.global['console']['markTimeline']) { + // TODO(user): markTimeline is deprecated. Drop this else clause entirely + // after Chrome M14 hits stable. + goog.global['console']['markTimeline'](msg); + } + } + + if (goog.global['msWriteProfilerMark']) { + // Logs a message to the Microsoft profiler + goog.global['msWriteProfilerMark'](msg); + } +}; + + +/** + * Gets the name of this logger. + * @return {string} The name of this logger. + */ +goog.debug.Logger.prototype.getName = function() { + return this.name_; +}; + + +/** + * Adds a handler to the logger. This doesn't use the event system because + * we want to be able to add logging to the event system. + * @param {Function} handler Handler function to add. + */ +goog.debug.Logger.prototype.addHandler = function(handler) { + if (goog.debug.LOGGING_ENABLED) { + if (goog.debug.Logger.ENABLE_HIERARCHY) { + if (!this.handlers_) { + this.handlers_ = []; + } + this.handlers_.push(handler); + } else { + goog.asserts.assert(!this.name_, + 'Cannot call addHandler on a non-root logger when ' + + 'goog.debug.Logger.ENABLE_HIERARCHY is false.'); + goog.debug.Logger.rootHandlers_.push(handler); + } + } +}; + + +/** + * Removes a handler from the logger. This doesn't use the event system because + * we want to be able to add logging to the event system. + * @param {Function} handler Handler function to remove. + * @return {boolean} Whether the handler was removed. + */ +goog.debug.Logger.prototype.removeHandler = function(handler) { + if (goog.debug.LOGGING_ENABLED) { + var handlers = goog.debug.Logger.ENABLE_HIERARCHY ? this.handlers_ : + goog.debug.Logger.rootHandlers_; + return !!handlers && goog.array.remove(handlers, handler); + } else { + return false; + } +}; + + +/** + * Returns the parent of this logger. + * @return {goog.debug.Logger} The parent logger or null if this is the root. + */ +goog.debug.Logger.prototype.getParent = function() { + return this.parent_; +}; + + +/** + * Returns the children of this logger as a map of the child name to the logger. + * @return {!Object} The map where the keys are the child leaf names and the + * values are the Logger objects. + */ +goog.debug.Logger.prototype.getChildren = function() { + if (!this.children_) { + this.children_ = {}; + } + return this.children_; +}; + + +/** + * Set the log level specifying which message levels will be logged by this + * logger. Message levels lower than this value will be discarded. + * The level value Level.OFF can be used to turn off logging. If the new level + * is null, it means that this node should inherit its level from its nearest + * ancestor with a specific (non-null) level value. + * + * @param {goog.debug.Logger.Level} level The new level. + */ +goog.debug.Logger.prototype.setLevel = function(level) { + if (goog.debug.LOGGING_ENABLED) { + if (goog.debug.Logger.ENABLE_HIERARCHY) { + this.level_ = level; + } else { + goog.asserts.assert(!this.name_, + 'Cannot call setLevel() on a non-root logger when ' + + 'goog.debug.Logger.ENABLE_HIERARCHY is false.'); + goog.debug.Logger.rootLevel_ = level; + } + } +}; + + +/** + * Gets the log level specifying which message levels will be logged by this + * logger. Message levels lower than this value will be discarded. + * The level value Level.OFF can be used to turn off logging. If the level + * is null, it means that this node should inherit its level from its nearest + * ancestor with a specific (non-null) level value. + * + * @return {goog.debug.Logger.Level} The level. + */ +goog.debug.Logger.prototype.getLevel = function() { + return goog.debug.LOGGING_ENABLED ? + this.level_ : goog.debug.Logger.Level.OFF; +}; + + +/** + * Returns the effective level of the logger based on its ancestors' levels. + * @return {goog.debug.Logger.Level} The level. + */ +goog.debug.Logger.prototype.getEffectiveLevel = function() { + if (!goog.debug.LOGGING_ENABLED) { + return goog.debug.Logger.Level.OFF; + } + + if (!goog.debug.Logger.ENABLE_HIERARCHY) { + return goog.debug.Logger.rootLevel_; + } + if (this.level_) { + return this.level_; + } + if (this.parent_) { + return this.parent_.getEffectiveLevel(); + } + goog.asserts.fail('Root logger has no level set.'); + return null; +}; + + +/** + * Checks if a message of the given level would actually be logged by this + * logger. This check is based on the Loggers effective level, which may be + * inherited from its parent. + * @param {goog.debug.Logger.Level} level The level to check. + * @return {boolean} Whether the message would be logged. + */ +goog.debug.Logger.prototype.isLoggable = function(level) { + return goog.debug.LOGGING_ENABLED && + level.value >= this.getEffectiveLevel().value; +}; + + +/** + * Logs a message. If the logger is currently enabled for the + * given message level then the given message is forwarded to all the + * registered output Handler objects. + * @param {goog.debug.Logger.Level} level One of the level identifiers. + * @param {goog.debug.Loggable} msg The message to log. + * @param {Error|Object=} opt_exception An exception associated with the + * message. + */ +goog.debug.Logger.prototype.log = function(level, msg, opt_exception) { + // java caches the effective level, not sure it's necessary here + if (goog.debug.LOGGING_ENABLED && this.isLoggable(level)) { + // Message callbacks can be useful when a log message is expensive to build. + if (goog.isFunction(msg)) { + msg = msg(); + } + + this.doLogRecord_(this.getLogRecord(level, msg, opt_exception)); + } +}; + + +/** + * Creates a new log record and adds the exception (if present) to it. + * @param {goog.debug.Logger.Level} level One of the level identifiers. + * @param {string} msg The string message. + * @param {Error|Object=} opt_exception An exception associated with the + * message. + * @return {!goog.debug.LogRecord} A log record. + * @suppress {es5Strict} + */ +goog.debug.Logger.prototype.getLogRecord = function( + level, msg, opt_exception) { + if (goog.debug.LogBuffer.isBufferingEnabled()) { + var logRecord = + goog.debug.LogBuffer.getInstance().addRecord(level, msg, this.name_); + } else { + logRecord = new goog.debug.LogRecord(level, String(msg), this.name_); + } + if (opt_exception) { + logRecord.setException(opt_exception); + } + return logRecord; +}; + + +/** + * Logs a message at the Logger.Level.SHOUT level. + * If the logger is currently enabled for the given message level then the + * given message is forwarded to all the registered output Handler objects. + * @param {goog.debug.Loggable} msg The message to log. + * @param {Error=} opt_exception An exception associated with the message. + */ +goog.debug.Logger.prototype.shout = function(msg, opt_exception) { + if (goog.debug.LOGGING_ENABLED) { + this.log(goog.debug.Logger.Level.SHOUT, msg, opt_exception); + } +}; + + +/** + * Logs a message at the Logger.Level.SEVERE level. + * If the logger is currently enabled for the given message level then the + * given message is forwarded to all the registered output Handler objects. + * @param {goog.debug.Loggable} msg The message to log. + * @param {Error=} opt_exception An exception associated with the message. + */ +goog.debug.Logger.prototype.severe = function(msg, opt_exception) { + if (goog.debug.LOGGING_ENABLED) { + this.log(goog.debug.Logger.Level.SEVERE, msg, opt_exception); + } +}; + + +/** + * Logs a message at the Logger.Level.WARNING level. + * If the logger is currently enabled for the given message level then the + * given message is forwarded to all the registered output Handler objects. + * @param {goog.debug.Loggable} msg The message to log. + * @param {Error=} opt_exception An exception associated with the message. + */ +goog.debug.Logger.prototype.warning = function(msg, opt_exception) { + if (goog.debug.LOGGING_ENABLED) { + this.log(goog.debug.Logger.Level.WARNING, msg, opt_exception); + } +}; + + +/** + * Logs a message at the Logger.Level.INFO level. + * If the logger is currently enabled for the given message level then the + * given message is forwarded to all the registered output Handler objects. + * @param {goog.debug.Loggable} msg The message to log. + * @param {Error=} opt_exception An exception associated with the message. + */ +goog.debug.Logger.prototype.info = function(msg, opt_exception) { + if (goog.debug.LOGGING_ENABLED) { + this.log(goog.debug.Logger.Level.INFO, msg, opt_exception); + } +}; + + +/** + * Logs a message at the Logger.Level.CONFIG level. + * If the logger is currently enabled for the given message level then the + * given message is forwarded to all the registered output Handler objects. + * @param {goog.debug.Loggable} msg The message to log. + * @param {Error=} opt_exception An exception associated with the message. + */ +goog.debug.Logger.prototype.config = function(msg, opt_exception) { + if (goog.debug.LOGGING_ENABLED) { + this.log(goog.debug.Logger.Level.CONFIG, msg, opt_exception); + } +}; + + +/** + * Logs a message at the Logger.Level.FINE level. + * If the logger is currently enabled for the given message level then the + * given message is forwarded to all the registered output Handler objects. + * @param {goog.debug.Loggable} msg The message to log. + * @param {Error=} opt_exception An exception associated with the message. + */ +goog.debug.Logger.prototype.fine = function(msg, opt_exception) { + if (goog.debug.LOGGING_ENABLED) { + this.log(goog.debug.Logger.Level.FINE, msg, opt_exception); + } +}; + + +/** + * Logs a message at the Logger.Level.FINER level. + * If the logger is currently enabled for the given message level then the + * given message is forwarded to all the registered output Handler objects. + * @param {goog.debug.Loggable} msg The message to log. + * @param {Error=} opt_exception An exception associated with the message. + */ +goog.debug.Logger.prototype.finer = function(msg, opt_exception) { + if (goog.debug.LOGGING_ENABLED) { + this.log(goog.debug.Logger.Level.FINER, msg, opt_exception); + } +}; + + +/** + * Logs a message at the Logger.Level.FINEST level. + * If the logger is currently enabled for the given message level then the + * given message is forwarded to all the registered output Handler objects. + * @param {goog.debug.Loggable} msg The message to log. + * @param {Error=} opt_exception An exception associated with the message. + */ +goog.debug.Logger.prototype.finest = function(msg, opt_exception) { + if (goog.debug.LOGGING_ENABLED) { + this.log(goog.debug.Logger.Level.FINEST, msg, opt_exception); + } +}; + + +/** + * Logs a LogRecord. If the logger is currently enabled for the + * given message level then the given message is forwarded to all the + * registered output Handler objects. + * @param {goog.debug.LogRecord} logRecord A log record to log. + */ +goog.debug.Logger.prototype.logRecord = function(logRecord) { + if (goog.debug.LOGGING_ENABLED && this.isLoggable(logRecord.getLevel())) { + this.doLogRecord_(logRecord); + } +}; + + +/** + * Logs a LogRecord. + * @param {goog.debug.LogRecord} logRecord A log record to log. + * @private + */ +goog.debug.Logger.prototype.doLogRecord_ = function(logRecord) { + goog.debug.Logger.logToProfilers('log:' + logRecord.getMessage()); + if (goog.debug.Logger.ENABLE_HIERARCHY) { + var target = this; + while (target) { + target.callPublish_(logRecord); + target = target.getParent(); + } + } else { + for (var i = 0, handler; handler = goog.debug.Logger.rootHandlers_[i++]; ) { + handler(logRecord); + } + } +}; + + +/** + * Calls the handlers for publish. + * @param {goog.debug.LogRecord} logRecord The log record to publish. + * @private + */ +goog.debug.Logger.prototype.callPublish_ = function(logRecord) { + if (this.handlers_) { + for (var i = 0, handler; handler = this.handlers_[i]; i++) { + handler(logRecord); + } + } +}; + + +/** + * Sets the parent of this logger. This is used for setting up the logger tree. + * @param {goog.debug.Logger} parent The parent logger. + * @private + */ +goog.debug.Logger.prototype.setParent_ = function(parent) { + this.parent_ = parent; +}; + + +/** + * Adds a child to this logger. This is used for setting up the logger tree. + * @param {string} name The leaf name of the child. + * @param {goog.debug.Logger} logger The child logger. + * @private + */ +goog.debug.Logger.prototype.addChild_ = function(name, logger) { + this.getChildren()[name] = logger; +}; + + +/** + * There is a single global LogManager object that is used to maintain a set of + * shared state about Loggers and log services. This is loosely based on the + * java class java.util.logging.LogManager. + * @const + */ +goog.debug.LogManager = {}; + + +/** + * Map of logger names to logger objects. + * + * @type {!Object<string, !goog.debug.Logger>} + * @private + */ +goog.debug.LogManager.loggers_ = {}; + + +/** + * The root logger which is the root of the logger tree. + * @type {goog.debug.Logger} + * @private + */ +goog.debug.LogManager.rootLogger_ = null; + + +/** + * Initializes the LogManager if not already initialized. + */ +goog.debug.LogManager.initialize = function() { + if (!goog.debug.LogManager.rootLogger_) { + goog.debug.LogManager.rootLogger_ = new goog.debug.Logger( + goog.debug.Logger.ROOT_LOGGER_NAME); + goog.debug.LogManager.loggers_[goog.debug.Logger.ROOT_LOGGER_NAME] = + goog.debug.LogManager.rootLogger_; + goog.debug.LogManager.rootLogger_.setLevel(goog.debug.Logger.Level.CONFIG); + } +}; + + +/** + * Returns all the loggers. + * @return {!Object<string, !goog.debug.Logger>} Map of logger names to logger + * objects. + */ +goog.debug.LogManager.getLoggers = function() { + return goog.debug.LogManager.loggers_; +}; + + +/** + * Returns the root of the logger tree namespace, the logger with the empty + * string as its name. + * + * @return {!goog.debug.Logger} The root logger. + */ +goog.debug.LogManager.getRoot = function() { + goog.debug.LogManager.initialize(); + return /** @type {!goog.debug.Logger} */ (goog.debug.LogManager.rootLogger_); +}; + + +/** + * Finds a named logger. + * + * @param {string} name A name for the logger. This should be a dot-separated + * name and should normally be based on the package name or class name of the + * subsystem, such as goog.net.BrowserChannel. + * @return {!goog.debug.Logger} The named logger. + */ +goog.debug.LogManager.getLogger = function(name) { + goog.debug.LogManager.initialize(); + var ret = goog.debug.LogManager.loggers_[name]; + return ret || goog.debug.LogManager.createLogger_(name); +}; + + +/** + * Creates a function that can be passed to goog.debug.catchErrors. The function + * will log all reported errors using the given logger. + * @param {goog.debug.Logger=} opt_logger The logger to log the errors to. + * Defaults to the root logger. + * @return {function(Object)} The created function. + */ +goog.debug.LogManager.createFunctionForCatchErrors = function(opt_logger) { + return function(info) { + var logger = opt_logger || goog.debug.LogManager.getRoot(); + logger.severe('Error: ' + info.message + ' (' + info.fileName + + ' @ Line: ' + info.line + ')'); + }; +}; + + +/** + * Creates the named logger. Will also create the parents of the named logger + * if they don't yet exist. + * @param {string} name The name of the logger. + * @return {!goog.debug.Logger} The named logger. + * @private + */ +goog.debug.LogManager.createLogger_ = function(name) { + // find parent logger + var logger = new goog.debug.Logger(name); + if (goog.debug.Logger.ENABLE_HIERARCHY) { + var lastDotIndex = name.lastIndexOf('.'); + var parentName = name.substr(0, lastDotIndex); + var leafName = name.substr(lastDotIndex + 1); + var parentLogger = goog.debug.LogManager.getLogger(parentName); + + // tell the parent about the child and the child about the parent + parentLogger.addChild_(leafName, logger); + logger.setParent_(parentLogger); + } + + goog.debug.LogManager.loggers_[name] = logger; + return logger; +}; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e2cad6e6/externs/GCL/externs/goog/debug/logrecord.js ---------------------------------------------------------------------- diff --git a/externs/GCL/externs/goog/debug/logrecord.js b/externs/GCL/externs/goog/debug/logrecord.js new file mode 100644 index 0000000..df5f982 --- /dev/null +++ b/externs/GCL/externs/goog/debug/logrecord.js @@ -0,0 +1,242 @@ +// Copyright 2006 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Definition of the LogRecord class. Please minimize + * dependencies this file has on other closure classes as any dependency it + * takes won't be able to use the logging infrastructure. + * + */ + +goog.provide('goog.debug.LogRecord'); + + + +/** + * LogRecord objects are used to pass logging requests between + * the logging framework and individual log Handlers. + * @constructor + * @param {goog.debug.Logger.Level} level One of the level identifiers. + * @param {string} msg The string message. + * @param {string} loggerName The name of the source logger. + * @param {number=} opt_time Time this log record was created if other than now. + * If 0, we use #goog.now. + * @param {number=} opt_sequenceNumber Sequence number of this log record. This + * should only be passed in when restoring a log record from persistence. + */ +goog.debug.LogRecord = function(level, msg, loggerName, + opt_time, opt_sequenceNumber) { + this.reset(level, msg, loggerName, opt_time, opt_sequenceNumber); +}; + + +/** + * Time the LogRecord was created. + * @type {number} + * @private + */ +goog.debug.LogRecord.prototype.time_; + + +/** + * Level of the LogRecord + * @type {goog.debug.Logger.Level} + * @private + */ +goog.debug.LogRecord.prototype.level_; + + +/** + * Message associated with the record + * @type {string} + * @private + */ +goog.debug.LogRecord.prototype.msg_; + + +/** + * Name of the logger that created the record. + * @type {string} + * @private + */ +goog.debug.LogRecord.prototype.loggerName_; + + +/** + * Sequence number for the LogRecord. Each record has a unique sequence number + * that is greater than all log records created before it. + * @type {number} + * @private + */ +goog.debug.LogRecord.prototype.sequenceNumber_ = 0; + + +/** + * Exception associated with the record + * @type {Object} + * @private + */ +goog.debug.LogRecord.prototype.exception_ = null; + + +/** + * @define {boolean} Whether to enable log sequence numbers. + */ +goog.define('goog.debug.LogRecord.ENABLE_SEQUENCE_NUMBERS', true); + + +/** + * A sequence counter for assigning increasing sequence numbers to LogRecord + * objects. + * @type {number} + * @private + */ +goog.debug.LogRecord.nextSequenceNumber_ = 0; + + +/** + * Sets all fields of the log record. + * @param {goog.debug.Logger.Level} level One of the level identifiers. + * @param {string} msg The string message. + * @param {string} loggerName The name of the source logger. + * @param {number=} opt_time Time this log record was created if other than now. + * If 0, we use #goog.now. + * @param {number=} opt_sequenceNumber Sequence number of this log record. This + * should only be passed in when restoring a log record from persistence. + */ +goog.debug.LogRecord.prototype.reset = function(level, msg, loggerName, + opt_time, opt_sequenceNumber) { + if (goog.debug.LogRecord.ENABLE_SEQUENCE_NUMBERS) { + this.sequenceNumber_ = typeof opt_sequenceNumber == 'number' ? + opt_sequenceNumber : goog.debug.LogRecord.nextSequenceNumber_++; + } + + this.time_ = opt_time || goog.now(); + this.level_ = level; + this.msg_ = msg; + this.loggerName_ = loggerName; + delete this.exception_; +}; + + +/** + * Get the source Logger's name. + * + * @return {string} source logger name (may be null). + */ +goog.debug.LogRecord.prototype.getLoggerName = function() { + return this.loggerName_; +}; + + +/** + * Get the exception that is part of the log record. + * + * @return {Object} the exception. + */ +goog.debug.LogRecord.prototype.getException = function() { + return this.exception_; +}; + + +/** + * Set the exception that is part of the log record. + * + * @param {Object} exception the exception. + */ +goog.debug.LogRecord.prototype.setException = function(exception) { + this.exception_ = exception; +}; + + +/** + * Get the source Logger's name. + * + * @param {string} loggerName source logger name (may be null). + */ +goog.debug.LogRecord.prototype.setLoggerName = function(loggerName) { + this.loggerName_ = loggerName; +}; + + +/** + * Get the logging message level, for example Level.SEVERE. + * @return {goog.debug.Logger.Level} the logging message level. + */ +goog.debug.LogRecord.prototype.getLevel = function() { + return this.level_; +}; + + +/** + * Set the logging message level, for example Level.SEVERE. + * @param {goog.debug.Logger.Level} level the logging message level. + */ +goog.debug.LogRecord.prototype.setLevel = function(level) { + this.level_ = level; +}; + + +/** + * Get the "raw" log message, before localization or formatting. + * + * @return {string} the raw message string. + */ +goog.debug.LogRecord.prototype.getMessage = function() { + return this.msg_; +}; + + +/** + * Set the "raw" log message, before localization or formatting. + * + * @param {string} msg the raw message string. + */ +goog.debug.LogRecord.prototype.setMessage = function(msg) { + this.msg_ = msg; +}; + + +/** + * Get event time in milliseconds since 1970. + * + * @return {number} event time in millis since 1970. + */ +goog.debug.LogRecord.prototype.getMillis = function() { + return this.time_; +}; + + +/** + * Set event time in milliseconds since 1970. + * + * @param {number} time event time in millis since 1970. + */ +goog.debug.LogRecord.prototype.setMillis = function(time) { + this.time_ = time; +}; + + +/** + * Get the sequence number. + * <p> + * Sequence numbers are normally assigned in the LogRecord + * constructor, which assigns unique sequence numbers to + * each new LogRecord in increasing order. + * @return {number} the sequence number. + */ +goog.debug.LogRecord.prototype.getSequenceNumber = function() { + return this.sequenceNumber_; +}; +
