Update wmts-hidpi, add nicer-api-docs
This commit is contained in:
183
nicer-api-docs/closure-library/closure/goog/log/log.js
Normal file
183
nicer-api-docs/closure-library/closure/goog/log/log.js
Normal file
@@ -0,0 +1,183 @@
|
||||
// Copyright 2013 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 Basic strippable logging definitions.
|
||||
* @see http://go/closurelogging
|
||||
*
|
||||
* @author johnlenz@google.com (John Lenz)
|
||||
*/
|
||||
|
||||
goog.provide('goog.log');
|
||||
goog.provide('goog.log.Level');
|
||||
goog.provide('goog.log.LogRecord');
|
||||
goog.provide('goog.log.Logger');
|
||||
|
||||
goog.require('goog.debug');
|
||||
goog.require('goog.debug.LogRecord');
|
||||
goog.require('goog.debug.Logger');
|
||||
|
||||
|
||||
/** @define {boolean} Whether logging is enabled. */
|
||||
goog.define('goog.log.ENABLED', goog.debug.LOGGING_ENABLED);
|
||||
|
||||
|
||||
|
||||
/** @constructor */
|
||||
goog.log.Logger = goog.debug.Logger;
|
||||
|
||||
|
||||
|
||||
/** @constructor */
|
||||
goog.log.Level = goog.debug.Logger.Level;
|
||||
|
||||
|
||||
|
||||
/** @constructor */
|
||||
goog.log.LogRecord = goog.debug.LogRecord;
|
||||
|
||||
|
||||
/**
|
||||
* 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 goog.debug.LogManager configuration and it will configured to also
|
||||
* send logging output to its parent's handlers.
|
||||
* @see goog.debug.LogManager
|
||||
*
|
||||
* @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.
|
||||
* @param {goog.log.Level=} opt_level If provided, override the
|
||||
* default logging level with the provided level.
|
||||
* @return {goog.log.Logger} The named logger or null if logging is disabled.
|
||||
*/
|
||||
goog.log.getLogger = function(name, opt_level) {
|
||||
if (goog.log.ENABLED) {
|
||||
var logger = goog.debug.Logger.getLogger(name);
|
||||
if (opt_level && logger) {
|
||||
logger.setLevel(opt_level);
|
||||
}
|
||||
return logger;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// TODO(johnlenz): try to tighten the types to these functions.
|
||||
/**
|
||||
* 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 {goog.log.Logger} logger
|
||||
* @param {Function} handler Handler function to add.
|
||||
*/
|
||||
goog.log.addHandler = function(logger, handler) {
|
||||
if (goog.log.ENABLED && logger) {
|
||||
logger.addHandler(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 {goog.log.Logger} logger
|
||||
* @param {Function} handler Handler function to remove.
|
||||
* @return {boolean} Whether the handler was removed.
|
||||
*/
|
||||
goog.log.removeHandler = function(logger, handler) {
|
||||
if (goog.log.ENABLED && logger) {
|
||||
return logger.removeHandler(handler);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 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.log.Logger} logger
|
||||
* @param {goog.log.Level} level One of the level identifiers.
|
||||
* @param {string} msg The string message.
|
||||
* @param {Error|Object=} opt_exception An exception associated with the
|
||||
* message.
|
||||
*/
|
||||
goog.log.log = function(logger, level, msg, opt_exception) {
|
||||
if (goog.log.ENABLED && logger) {
|
||||
logger.log(level, msg, opt_exception);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Logs a message at the 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.log.Logger} logger
|
||||
* @param {string} msg The string message.
|
||||
* @param {Error=} opt_exception An exception associated with the message.
|
||||
*/
|
||||
goog.log.error = function(logger, msg, opt_exception) {
|
||||
if (goog.log.ENABLED && logger) {
|
||||
logger.severe(msg, opt_exception);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Logs a message at the 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.log.Logger} logger
|
||||
* @param {string} msg The string message.
|
||||
* @param {Error=} opt_exception An exception associated with the message.
|
||||
*/
|
||||
goog.log.warning = function(logger, msg, opt_exception) {
|
||||
if (goog.log.ENABLED && logger) {
|
||||
logger.warning(msg, opt_exception);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Logs a message at the 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.log.Logger} logger
|
||||
* @param {string} msg The string message.
|
||||
* @param {Error=} opt_exception An exception associated with the message.
|
||||
*/
|
||||
goog.log.info = function(logger, msg, opt_exception) {
|
||||
if (goog.log.ENABLED && logger) {
|
||||
logger.info(msg, opt_exception);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Logs a message at the 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.log.Logger} logger
|
||||
* @param {string} msg The string message.
|
||||
* @param {Error=} opt_exception An exception associated with the message.
|
||||
*/
|
||||
goog.log.fine = function(logger, msg, opt_exception) {
|
||||
if (goog.log.ENABLED && logger) {
|
||||
logger.fine(msg, opt_exception);
|
||||
}
|
||||
};
|
||||
169
nicer-api-docs/closure-library/closure/goog/log/log_test.js
Normal file
169
nicer-api-docs/closure-library/closure/goog/log/log_test.js
Normal file
@@ -0,0 +1,169 @@
|
||||
// Copyright 2013 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 Unit tests for goog.log.
|
||||
*/
|
||||
|
||||
/** @suppress {extraProvide} */
|
||||
goog.provide('goog.logTest');
|
||||
|
||||
goog.require('goog.debug.LogManager');
|
||||
goog.require('goog.log');
|
||||
goog.require('goog.log.Level');
|
||||
goog.require('goog.testing.jsunit');
|
||||
|
||||
|
||||
|
||||
goog.setTestOnly('goog.logTest');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A simple log handler that remembers the last record published.
|
||||
* @constructor
|
||||
* @private
|
||||
*/
|
||||
function TestHandler_() {
|
||||
this.logRecord = null;
|
||||
}
|
||||
|
||||
TestHandler_.prototype.onPublish = function(logRecord) {
|
||||
this.logRecord = logRecord;
|
||||
};
|
||||
|
||||
|
||||
TestHandler_.prototype.reset = function() {
|
||||
this.logRecord = null;
|
||||
};
|
||||
|
||||
|
||||
function testParents() {
|
||||
var logger2sibling1 = goog.log.getLogger('goog.test');
|
||||
var logger2sibling2 = goog.log.getLogger('goog.bar');
|
||||
var logger3sibling1 = goog.log.getLogger('goog.bar.foo');
|
||||
var logger3siblint2 = goog.log.getLogger('goog.bar.baaz');
|
||||
var rootLogger = goog.debug.LogManager.getRoot();
|
||||
var googLogger = goog.log.getLogger('goog');
|
||||
assertEquals(rootLogger, googLogger.getParent());
|
||||
assertEquals(googLogger, logger2sibling1.getParent());
|
||||
assertEquals(googLogger, logger2sibling2.getParent());
|
||||
assertEquals(logger2sibling2, logger3sibling1.getParent());
|
||||
assertEquals(logger2sibling2, logger3siblint2.getParent());
|
||||
}
|
||||
|
||||
function testLogging1() {
|
||||
var root = goog.debug.LogManager.getRoot();
|
||||
var handler = new TestHandler_();
|
||||
var f = goog.bind(handler.onPublish, handler);
|
||||
goog.log.addHandler(root, f);
|
||||
var logger = goog.log.getLogger('goog.bar.baaz');
|
||||
goog.log.log(logger, goog.log.Level.WARNING, 'foo');
|
||||
assertNotNull(handler.logRecord);
|
||||
assertEquals(goog.log.Level.WARNING, handler.logRecord.getLevel());
|
||||
assertEquals('foo', handler.logRecord.getMessage());
|
||||
handler.logRecord = null;
|
||||
|
||||
goog.log.removeHandler(root, f);
|
||||
goog.log.log(logger, goog.log.Level.WARNING, 'foo');
|
||||
assertNull(handler.logRecord);
|
||||
}
|
||||
|
||||
function testLogging2() {
|
||||
var root = goog.debug.LogManager.getRoot();
|
||||
var handler = new TestHandler_();
|
||||
var f = goog.bind(handler.onPublish, handler);
|
||||
goog.log.addHandler(root, f);
|
||||
var logger = goog.log.getLogger('goog.bar.baaz');
|
||||
goog.log.warning(logger, 'foo');
|
||||
assertNotNull(handler.logRecord);
|
||||
assertEquals(goog.log.Level.WARNING, handler.logRecord.getLevel());
|
||||
assertEquals('foo', handler.logRecord.getMessage());
|
||||
handler.logRecord = null;
|
||||
|
||||
goog.log.removeHandler(root, f);
|
||||
goog.log.log(logger, goog.log.Level.WARNING, 'foo');
|
||||
assertNull(handler.logRecord);
|
||||
}
|
||||
|
||||
|
||||
function testFiltering() {
|
||||
var root = goog.debug.LogManager.getRoot();
|
||||
var handler = new TestHandler_();
|
||||
var f = goog.bind(handler.onPublish, handler);
|
||||
root.addHandler(f);
|
||||
var logger1 = goog.log.getLogger('goog.bar.foo', goog.log.Level.WARNING);
|
||||
var logger2 = goog.log.getLogger('goog.bar.baaz', goog.log.Level.INFO);
|
||||
goog.log.warning(logger2, 'foo');
|
||||
assertNotNull(handler.logRecord);
|
||||
assertEquals(goog.log.Level.WARNING, handler.logRecord.getLevel());
|
||||
assertEquals('foo', handler.logRecord.getMessage());
|
||||
handler.reset();
|
||||
goog.log.info(logger1, 'bar');
|
||||
assertNull(handler.logRecord);
|
||||
goog.log.warning(logger1, 'baaz');
|
||||
assertNotNull(handler.logRecord);
|
||||
handler.reset();
|
||||
goog.log.error(logger1, 'baaz');
|
||||
assertNotNull(handler.logRecord);
|
||||
}
|
||||
|
||||
|
||||
function testException() {
|
||||
var root = goog.debug.LogManager.getRoot();
|
||||
var handler = new TestHandler_();
|
||||
var f = goog.bind(handler.onPublish, handler);
|
||||
root.addHandler(f);
|
||||
var logger = goog.log.getLogger('goog.debug.logger_test');
|
||||
var ex = Error('boo!');
|
||||
goog.log.error(logger, 'hello', ex);
|
||||
assertNotNull(handler.logRecord);
|
||||
assertEquals(goog.log.Level.SEVERE, handler.logRecord.getLevel());
|
||||
assertEquals('hello', handler.logRecord.getMessage());
|
||||
assertEquals(ex, handler.logRecord.getException());
|
||||
assertEquals('Message: boo!',
|
||||
handler.logRecord.getExceptionText().substring(0, 13));
|
||||
}
|
||||
|
||||
|
||||
function testGetLogRecord() {
|
||||
var name = 'test.get.log.record';
|
||||
var level = goog.log.Level.FINE;
|
||||
var msg = 'msg';
|
||||
|
||||
var logger = goog.log.getLogger(name);
|
||||
var logRecord = logger.getLogRecord(level, msg);
|
||||
|
||||
assertEquals(name, logRecord.getLoggerName());
|
||||
assertEquals(level, logRecord.getLevel());
|
||||
assertEquals(msg, logRecord.getMessage());
|
||||
|
||||
assertNull(logRecord.getException());
|
||||
}
|
||||
|
||||
function testGetLogRecordWithException() {
|
||||
var name = 'test.get.log.record';
|
||||
var level = goog.log.Level.FINE;
|
||||
var msg = 'msg';
|
||||
var ex = Error('Hi');
|
||||
|
||||
var logger = goog.log.getLogger(name);
|
||||
var logRecord = logger.getLogRecord(level, msg, ex);
|
||||
|
||||
assertEquals(name, logRecord.getLoggerName());
|
||||
assertEquals(level, logRecord.getLevel());
|
||||
assertEquals(msg, logRecord.getMessage());
|
||||
assertEquals(ex, logRecord.getException());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user