Path: blob/trunk/third_party/closure/goog/debug/logger.js
2868 views
// Copyright 2006 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Definition of the Logger class. Please minimize dependencies16* this file has on other closure classes as any dependency it takes won't be17* able to use the logging infrastructure.18*19* @see ../demos/debug.html20*/2122goog.provide('goog.debug.LogManager');23goog.provide('goog.debug.Loggable');24goog.provide('goog.debug.Logger');25goog.provide('goog.debug.Logger.Level');2627goog.require('goog.array');28goog.require('goog.asserts');29goog.require('goog.debug');30goog.require('goog.debug.LogBuffer');31goog.require('goog.debug.LogRecord');323334/**35* A message value that can be handled by a Logger.36*37* Functions are treated like callbacks, but are only called when the event's38* log level is enabled. This is useful for logging messages that are expensive39* to construct.40*41* @typedef {string|function(): string}42*/43goog.debug.Loggable;44454647/**48* The Logger is an object used for logging debug messages. Loggers are49* normally named, using a hierarchical dot-separated namespace. Logger names50* can be arbitrary strings, but they should normally be based on the package51* name or class name of the logged component, such as goog.net.BrowserChannel.52*53* The Logger object is loosely based on the java class54* java.util.logging.Logger. It supports different levels of filtering for55* different loggers.56*57* The logger object should never be instantiated by application code. It58* should always use the goog.debug.Logger.getLogger function.59*60* @constructor61* @param {string} name The name of the Logger.62* @final63*/64goog.debug.Logger = function(name) {65/**66* Name of the Logger. Generally a dot-separated namespace67* @private {string}68*/69this.name_ = name;7071/**72* Parent Logger.73* @private {goog.debug.Logger}74*/75this.parent_ = null;7677/**78* Level that this logger only filters above. Null indicates it should79* inherit from the parent.80* @private {goog.debug.Logger.Level}81*/82this.level_ = null;8384/**85* Map of children loggers. The keys are the leaf names of the children and86* the values are the child loggers.87* @private {Object}88*/89this.children_ = null;9091/**92* Handlers that are listening to this logger.93* @private {Array<Function>}94*/95this.handlers_ = null;96};979899/** @const */100goog.debug.Logger.ROOT_LOGGER_NAME = '';101102103/**104* @define {boolean} Toggles whether loggers other than the root logger can have105* log handlers attached to them and whether they can have their log level106* set. Logging is a bit faster when this is set to false.107*/108goog.define('goog.debug.Logger.ENABLE_HIERARCHY', true);109110111if (!goog.debug.Logger.ENABLE_HIERARCHY) {112/**113* @type {!Array<Function>}114* @private115*/116goog.debug.Logger.rootHandlers_ = [];117118119/**120* @type {goog.debug.Logger.Level}121* @private122*/123goog.debug.Logger.rootLevel_;124}125126127128/**129* The Level class defines a set of standard logging levels that130* can be used to control logging output. The logging Level objects131* are ordered and are specified by ordered integers. Enabling logging132* at a given level also enables logging at all higher levels.133* <p>134* Clients should normally use the predefined Level constants such135* as Level.SEVERE.136* <p>137* The levels in descending order are:138* <ul>139* <li>SEVERE (highest value)140* <li>WARNING141* <li>INFO142* <li>CONFIG143* <li>FINE144* <li>FINER145* <li>FINEST (lowest value)146* </ul>147* In addition there is a level OFF that can be used to turn148* off logging, and a level ALL that can be used to enable149* logging of all messages.150*151* @param {string} name The name of the level.152* @param {number} value The numeric value of the level.153* @constructor154* @final155*/156goog.debug.Logger.Level = function(name, value) {157/**158* The name of the level159* @type {string}160*/161this.name = name;162163/**164* The numeric value of the level165* @type {number}166*/167this.value = value;168};169170171/**172* @return {string} String representation of the logger level.173* @override174*/175goog.debug.Logger.Level.prototype.toString = function() {176return this.name;177};178179180/**181* OFF is a special level that can be used to turn off logging.182* This level is initialized to <CODE>Infinity</CODE>.183* @type {!goog.debug.Logger.Level}184*/185goog.debug.Logger.Level.OFF = new goog.debug.Logger.Level('OFF', Infinity);186187188/**189* SHOUT is a message level for extra debugging loudness.190* This level is initialized to <CODE>1200</CODE>.191* @type {!goog.debug.Logger.Level}192*/193goog.debug.Logger.Level.SHOUT = new goog.debug.Logger.Level('SHOUT', 1200);194195196/**197* SEVERE is a message level indicating a serious failure.198* This level is initialized to <CODE>1000</CODE>.199* @type {!goog.debug.Logger.Level}200*/201goog.debug.Logger.Level.SEVERE = new goog.debug.Logger.Level('SEVERE', 1000);202203204/**205* WARNING is a message level indicating a potential problem.206* This level is initialized to <CODE>900</CODE>.207* @type {!goog.debug.Logger.Level}208*/209goog.debug.Logger.Level.WARNING = new goog.debug.Logger.Level('WARNING', 900);210211212/**213* INFO is a message level for informational messages.214* This level is initialized to <CODE>800</CODE>.215* @type {!goog.debug.Logger.Level}216*/217goog.debug.Logger.Level.INFO = new goog.debug.Logger.Level('INFO', 800);218219220/**221* CONFIG is a message level for static configuration messages.222* This level is initialized to <CODE>700</CODE>.223* @type {!goog.debug.Logger.Level}224*/225goog.debug.Logger.Level.CONFIG = new goog.debug.Logger.Level('CONFIG', 700);226227228/**229* FINE is a message level providing tracing information.230* This level is initialized to <CODE>500</CODE>.231* @type {!goog.debug.Logger.Level}232*/233goog.debug.Logger.Level.FINE = new goog.debug.Logger.Level('FINE', 500);234235236/**237* FINER indicates a fairly detailed tracing message.238* This level is initialized to <CODE>400</CODE>.239* @type {!goog.debug.Logger.Level}240*/241goog.debug.Logger.Level.FINER = new goog.debug.Logger.Level('FINER', 400);242243/**244* FINEST indicates a highly detailed tracing message.245* This level is initialized to <CODE>300</CODE>.246* @type {!goog.debug.Logger.Level}247*/248249goog.debug.Logger.Level.FINEST = new goog.debug.Logger.Level('FINEST', 300);250251252/**253* ALL indicates that all messages should be logged.254* This level is initialized to <CODE>0</CODE>.255* @type {!goog.debug.Logger.Level}256*/257goog.debug.Logger.Level.ALL = new goog.debug.Logger.Level('ALL', 0);258259260/**261* The predefined levels.262* @type {!Array<!goog.debug.Logger.Level>}263* @final264*/265goog.debug.Logger.Level.PREDEFINED_LEVELS = [266goog.debug.Logger.Level.OFF, goog.debug.Logger.Level.SHOUT,267goog.debug.Logger.Level.SEVERE, goog.debug.Logger.Level.WARNING,268goog.debug.Logger.Level.INFO, goog.debug.Logger.Level.CONFIG,269goog.debug.Logger.Level.FINE, goog.debug.Logger.Level.FINER,270goog.debug.Logger.Level.FINEST, goog.debug.Logger.Level.ALL271];272273274/**275* A lookup map used to find the level object based on the name or value of276* the level object.277* @type {Object}278* @private279*/280goog.debug.Logger.Level.predefinedLevelsCache_ = null;281282283/**284* Creates the predefined levels cache and populates it.285* @private286*/287goog.debug.Logger.Level.createPredefinedLevelsCache_ = function() {288goog.debug.Logger.Level.predefinedLevelsCache_ = {};289for (var i = 0, level; level = goog.debug.Logger.Level.PREDEFINED_LEVELS[i];290i++) {291goog.debug.Logger.Level.predefinedLevelsCache_[level.value] = level;292goog.debug.Logger.Level.predefinedLevelsCache_[level.name] = level;293}294};295296297/**298* Gets the predefined level with the given name.299* @param {string} name The name of the level.300* @return {goog.debug.Logger.Level} The level, or null if none found.301*/302goog.debug.Logger.Level.getPredefinedLevel = function(name) {303if (!goog.debug.Logger.Level.predefinedLevelsCache_) {304goog.debug.Logger.Level.createPredefinedLevelsCache_();305}306307return goog.debug.Logger.Level.predefinedLevelsCache_[name] || null;308};309310311/**312* Gets the highest predefined level <= #value.313* @param {number} value Level value.314* @return {goog.debug.Logger.Level} The level, or null if none found.315*/316goog.debug.Logger.Level.getPredefinedLevelByValue = function(value) {317if (!goog.debug.Logger.Level.predefinedLevelsCache_) {318goog.debug.Logger.Level.createPredefinedLevelsCache_();319}320321if (value in /** @type {!Object} */ (322goog.debug.Logger.Level.predefinedLevelsCache_)) {323return goog.debug.Logger.Level.predefinedLevelsCache_[value];324}325326for (var i = 0; i < goog.debug.Logger.Level.PREDEFINED_LEVELS.length; ++i) {327var level = goog.debug.Logger.Level.PREDEFINED_LEVELS[i];328if (level.value <= value) {329return level;330}331}332return null;333};334335336/**337* Finds or creates a logger for a named subsystem. If a logger has already been338* created with the given name it is returned. Otherwise a new logger is339* created. If a new logger is created its log level will be configured based340* on the LogManager configuration and it will configured to also send logging341* output to its parent's handlers. It will be registered in the LogManager342* global namespace.343*344* @param {string} name A name for the logger. This should be a dot-separated345* name and should normally be based on the package name or class name of the346* subsystem, such as goog.net.BrowserChannel.347* @return {!goog.debug.Logger} The named logger.348* @deprecated use {@link goog.log} instead.349*/350goog.debug.Logger.getLogger = function(name) {351return goog.debug.LogManager.getLogger(name);352};353354355/**356* Logs a message to profiling tools, if available.357* {@see https://developers.google.com/web-toolkit/speedtracer/logging-api}358* {@see http://msdn.microsoft.com/en-us/library/dd433074(VS.85).aspx}359* @param {string} msg The message to log.360*/361goog.debug.Logger.logToProfilers = function(msg) {362// Using goog.global, as loggers might be used in window-less contexts.363if (goog.global['console']) {364if (goog.global['console']['timeStamp']) {365// Logs a message to Firebug, Web Inspector, SpeedTracer, etc.366goog.global['console']['timeStamp'](msg);367} else if (goog.global['console']['markTimeline']) {368// TODO(user): markTimeline is deprecated. Drop this else clause entirely369// after Chrome M14 hits stable.370goog.global['console']['markTimeline'](msg);371}372}373374if (goog.global['msWriteProfilerMark']) {375// Logs a message to the Microsoft profiler376goog.global['msWriteProfilerMark'](msg);377}378};379380381/**382* Gets the name of this logger.383* @return {string} The name of this logger.384*/385goog.debug.Logger.prototype.getName = function() {386return this.name_;387};388389390/**391* Adds a handler to the logger. This doesn't use the event system because392* we want to be able to add logging to the event system.393* @param {Function} handler Handler function to add.394*/395goog.debug.Logger.prototype.addHandler = function(handler) {396if (goog.debug.LOGGING_ENABLED) {397if (goog.debug.Logger.ENABLE_HIERARCHY) {398if (!this.handlers_) {399this.handlers_ = [];400}401this.handlers_.push(handler);402} else {403goog.asserts.assert(404!this.name_, 'Cannot call addHandler on a non-root logger when ' +405'goog.debug.Logger.ENABLE_HIERARCHY is false.');406goog.debug.Logger.rootHandlers_.push(handler);407}408}409};410411412/**413* Removes a handler from the logger. This doesn't use the event system because414* we want to be able to add logging to the event system.415* @param {Function} handler Handler function to remove.416* @return {boolean} Whether the handler was removed.417*/418goog.debug.Logger.prototype.removeHandler = function(handler) {419if (goog.debug.LOGGING_ENABLED) {420var handlers = goog.debug.Logger.ENABLE_HIERARCHY ?421this.handlers_ :422goog.debug.Logger.rootHandlers_;423return !!handlers && goog.array.remove(handlers, handler);424} else {425return false;426}427};428429430/**431* Returns the parent of this logger.432* @return {goog.debug.Logger} The parent logger or null if this is the root.433*/434goog.debug.Logger.prototype.getParent = function() {435return this.parent_;436};437438439/**440* Returns the children of this logger as a map of the child name to the logger.441* @return {!Object} The map where the keys are the child leaf names and the442* values are the Logger objects.443*/444goog.debug.Logger.prototype.getChildren = function() {445if (!this.children_) {446this.children_ = {};447}448return this.children_;449};450451452/**453* Set the log level specifying which message levels will be logged by this454* logger. Message levels lower than this value will be discarded.455* The level value Level.OFF can be used to turn off logging. If the new level456* is null, it means that this node should inherit its level from its nearest457* ancestor with a specific (non-null) level value.458*459* @param {goog.debug.Logger.Level} level The new level.460*/461goog.debug.Logger.prototype.setLevel = function(level) {462if (goog.debug.LOGGING_ENABLED) {463if (goog.debug.Logger.ENABLE_HIERARCHY) {464this.level_ = level;465} else {466goog.asserts.assert(467!this.name_, 'Cannot call setLevel() on a non-root logger when ' +468'goog.debug.Logger.ENABLE_HIERARCHY is false.');469goog.debug.Logger.rootLevel_ = level;470}471}472};473474475/**476* Gets the log level specifying which message levels will be logged by this477* logger. Message levels lower than this value will be discarded.478* The level value Level.OFF can be used to turn off logging. If the level479* is null, it means that this node should inherit its level from its nearest480* ancestor with a specific (non-null) level value.481*482* @return {goog.debug.Logger.Level} The level.483*/484goog.debug.Logger.prototype.getLevel = function() {485return goog.debug.LOGGING_ENABLED ? this.level_ : goog.debug.Logger.Level.OFF;486};487488489/**490* Returns the effective level of the logger based on its ancestors' levels.491* @return {goog.debug.Logger.Level} The level.492*/493goog.debug.Logger.prototype.getEffectiveLevel = function() {494if (!goog.debug.LOGGING_ENABLED) {495return goog.debug.Logger.Level.OFF;496}497498if (!goog.debug.Logger.ENABLE_HIERARCHY) {499return goog.debug.Logger.rootLevel_;500}501if (this.level_) {502return this.level_;503}504if (this.parent_) {505return this.parent_.getEffectiveLevel();506}507goog.asserts.fail('Root logger has no level set.');508return null;509};510511512/**513* Checks if a message of the given level would actually be logged by this514* logger. This check is based on the Loggers effective level, which may be515* inherited from its parent.516* @param {goog.debug.Logger.Level} level The level to check.517* @return {boolean} Whether the message would be logged.518*/519goog.debug.Logger.prototype.isLoggable = function(level) {520return goog.debug.LOGGING_ENABLED &&521level.value >= this.getEffectiveLevel().value;522};523524525/**526* Logs a message. If the logger is currently enabled for the527* given message level then the given message is forwarded to all the528* registered output Handler objects.529* @param {goog.debug.Logger.Level} level One of the level identifiers.530* @param {goog.debug.Loggable} msg The message to log.531* @param {Error|Object=} opt_exception An exception associated with the532* message.533*/534goog.debug.Logger.prototype.log = function(level, msg, opt_exception) {535// java caches the effective level, not sure it's necessary here536if (goog.debug.LOGGING_ENABLED && this.isLoggable(level)) {537// Message callbacks can be useful when a log message is expensive to build.538if (goog.isFunction(msg)) {539msg = msg();540}541542this.doLogRecord_(this.getLogRecord(level, msg, opt_exception));543}544};545546547/**548* Creates a new log record and adds the exception (if present) to it.549* @param {goog.debug.Logger.Level} level One of the level identifiers.550* @param {string} msg The string message.551* @param {Error|Object=} opt_exception An exception associated with the552* message.553* @return {!goog.debug.LogRecord} A log record.554* @suppress {es5Strict}555*/556goog.debug.Logger.prototype.getLogRecord = function(level, msg, opt_exception) {557if (goog.debug.LogBuffer.isBufferingEnabled()) {558var logRecord =559goog.debug.LogBuffer.getInstance().addRecord(level, msg, this.name_);560} else {561logRecord = new goog.debug.LogRecord(level, String(msg), this.name_);562}563if (opt_exception) {564logRecord.setException(opt_exception);565}566return logRecord;567};568569570/**571* Logs a message at the Logger.Level.SHOUT level.572* If the logger is currently enabled for the given message level then the573* given message is forwarded to all the registered output Handler objects.574* @param {goog.debug.Loggable} msg The message to log.575* @param {Error=} opt_exception An exception associated with the message.576*/577goog.debug.Logger.prototype.shout = function(msg, opt_exception) {578if (goog.debug.LOGGING_ENABLED) {579this.log(goog.debug.Logger.Level.SHOUT, msg, opt_exception);580}581};582583584/**585* Logs a message at the Logger.Level.SEVERE level.586* If the logger is currently enabled for the given message level then the587* given message is forwarded to all the registered output Handler objects.588* @param {goog.debug.Loggable} msg The message to log.589* @param {Error=} opt_exception An exception associated with the message.590*/591goog.debug.Logger.prototype.severe = function(msg, opt_exception) {592if (goog.debug.LOGGING_ENABLED) {593this.log(goog.debug.Logger.Level.SEVERE, msg, opt_exception);594}595};596597598/**599* Logs a message at the Logger.Level.WARNING level.600* If the logger is currently enabled for the given message level then the601* given message is forwarded to all the registered output Handler objects.602* @param {goog.debug.Loggable} msg The message to log.603* @param {Error=} opt_exception An exception associated with the message.604*/605goog.debug.Logger.prototype.warning = function(msg, opt_exception) {606if (goog.debug.LOGGING_ENABLED) {607this.log(goog.debug.Logger.Level.WARNING, msg, opt_exception);608}609};610611612/**613* Logs a message at the Logger.Level.INFO level.614* If the logger is currently enabled for the given message level then the615* given message is forwarded to all the registered output Handler objects.616* @param {goog.debug.Loggable} msg The message to log.617* @param {Error=} opt_exception An exception associated with the message.618*/619goog.debug.Logger.prototype.info = function(msg, opt_exception) {620if (goog.debug.LOGGING_ENABLED) {621this.log(goog.debug.Logger.Level.INFO, msg, opt_exception);622}623};624625626/**627* Logs a message at the Logger.Level.CONFIG level.628* If the logger is currently enabled for the given message level then the629* given message is forwarded to all the registered output Handler objects.630* @param {goog.debug.Loggable} msg The message to log.631* @param {Error=} opt_exception An exception associated with the message.632*/633goog.debug.Logger.prototype.config = function(msg, opt_exception) {634if (goog.debug.LOGGING_ENABLED) {635this.log(goog.debug.Logger.Level.CONFIG, msg, opt_exception);636}637};638639640/**641* Logs a message at the Logger.Level.FINE level.642* If the logger is currently enabled for the given message level then the643* given message is forwarded to all the registered output Handler objects.644* @param {goog.debug.Loggable} msg The message to log.645* @param {Error=} opt_exception An exception associated with the message.646*/647goog.debug.Logger.prototype.fine = function(msg, opt_exception) {648if (goog.debug.LOGGING_ENABLED) {649this.log(goog.debug.Logger.Level.FINE, msg, opt_exception);650}651};652653654/**655* Logs a message at the Logger.Level.FINER level.656* If the logger is currently enabled for the given message level then the657* given message is forwarded to all the registered output Handler objects.658* @param {goog.debug.Loggable} msg The message to log.659* @param {Error=} opt_exception An exception associated with the message.660*/661goog.debug.Logger.prototype.finer = function(msg, opt_exception) {662if (goog.debug.LOGGING_ENABLED) {663this.log(goog.debug.Logger.Level.FINER, msg, opt_exception);664}665};666667668/**669* Logs a message at the Logger.Level.FINEST level.670* If the logger is currently enabled for the given message level then the671* given message is forwarded to all the registered output Handler objects.672* @param {goog.debug.Loggable} msg The message to log.673* @param {Error=} opt_exception An exception associated with the message.674*/675goog.debug.Logger.prototype.finest = function(msg, opt_exception) {676if (goog.debug.LOGGING_ENABLED) {677this.log(goog.debug.Logger.Level.FINEST, msg, opt_exception);678}679};680681682/**683* Logs a LogRecord. If the logger is currently enabled for the684* given message level then the given message is forwarded to all the685* registered output Handler objects.686* @param {goog.debug.LogRecord} logRecord A log record to log.687*/688goog.debug.Logger.prototype.logRecord = function(logRecord) {689if (goog.debug.LOGGING_ENABLED && this.isLoggable(logRecord.getLevel())) {690this.doLogRecord_(logRecord);691}692};693694695/**696* Logs a LogRecord.697* @param {goog.debug.LogRecord} logRecord A log record to log.698* @private699*/700goog.debug.Logger.prototype.doLogRecord_ = function(logRecord) {701goog.debug.Logger.logToProfilers('log:' + logRecord.getMessage());702if (goog.debug.Logger.ENABLE_HIERARCHY) {703var target = this;704while (target) {705target.callPublish_(logRecord);706target = target.getParent();707}708} else {709for (var i = 0, handler; handler = goog.debug.Logger.rootHandlers_[i++];) {710handler(logRecord);711}712}713};714715716/**717* Calls the handlers for publish.718* @param {goog.debug.LogRecord} logRecord The log record to publish.719* @private720*/721goog.debug.Logger.prototype.callPublish_ = function(logRecord) {722if (this.handlers_) {723for (var i = 0, handler; handler = this.handlers_[i]; i++) {724handler(logRecord);725}726}727};728729730/**731* Sets the parent of this logger. This is used for setting up the logger tree.732* @param {goog.debug.Logger} parent The parent logger.733* @private734*/735goog.debug.Logger.prototype.setParent_ = function(parent) {736this.parent_ = parent;737};738739740/**741* Adds a child to this logger. This is used for setting up the logger tree.742* @param {string} name The leaf name of the child.743* @param {goog.debug.Logger} logger The child logger.744* @private745*/746goog.debug.Logger.prototype.addChild_ = function(name, logger) {747this.getChildren()[name] = logger;748};749750751/**752* There is a single global LogManager object that is used to maintain a set of753* shared state about Loggers and log services. This is loosely based on the754* java class java.util.logging.LogManager.755* @const756*/757goog.debug.LogManager = {};758759760/**761* Map of logger names to logger objects.762*763* @type {!Object<string, !goog.debug.Logger>}764* @private765*/766goog.debug.LogManager.loggers_ = {};767768769/**770* The root logger which is the root of the logger tree.771* @type {goog.debug.Logger}772* @private773*/774goog.debug.LogManager.rootLogger_ = null;775776777/**778* Initializes the LogManager if not already initialized.779*/780goog.debug.LogManager.initialize = function() {781if (!goog.debug.LogManager.rootLogger_) {782goog.debug.LogManager.rootLogger_ =783new goog.debug.Logger(goog.debug.Logger.ROOT_LOGGER_NAME);784goog.debug.LogManager.loggers_[goog.debug.Logger.ROOT_LOGGER_NAME] =785goog.debug.LogManager.rootLogger_;786goog.debug.LogManager.rootLogger_.setLevel(goog.debug.Logger.Level.CONFIG);787}788};789790791/**792* Returns all the loggers.793* @return {!Object<string, !goog.debug.Logger>} Map of logger names to logger794* objects.795*/796goog.debug.LogManager.getLoggers = function() {797return goog.debug.LogManager.loggers_;798};799800801/**802* Returns the root of the logger tree namespace, the logger with the empty803* string as its name.804*805* @return {!goog.debug.Logger} The root logger.806*/807goog.debug.LogManager.getRoot = function() {808goog.debug.LogManager.initialize();809return /** @type {!goog.debug.Logger} */ (goog.debug.LogManager.rootLogger_);810};811812813/**814* Finds a named logger.815*816* @param {string} name A name for the logger. This should be a dot-separated817* name and should normally be based on the package name or class name of the818* subsystem, such as goog.net.BrowserChannel.819* @return {!goog.debug.Logger} The named logger.820*/821goog.debug.LogManager.getLogger = function(name) {822goog.debug.LogManager.initialize();823var ret = goog.debug.LogManager.loggers_[name];824return ret || goog.debug.LogManager.createLogger_(name);825};826827828/**829* Creates a function that can be passed to goog.debug.catchErrors. The function830* will log all reported errors using the given logger.831* @param {goog.debug.Logger=} opt_logger The logger to log the errors to.832* Defaults to the root logger.833* @return {function(Object)} The created function.834*/835goog.debug.LogManager.createFunctionForCatchErrors = function(opt_logger) {836return function(info) {837var logger = opt_logger || goog.debug.LogManager.getRoot();838logger.severe(839'Error: ' + info.message + ' (' + info.fileName + ' @ Line: ' +840info.line + ')');841};842};843844845/**846* Creates the named logger. Will also create the parents of the named logger847* if they don't yet exist.848* @param {string} name The name of the logger.849* @return {!goog.debug.Logger} The named logger.850* @private851*/852goog.debug.LogManager.createLogger_ = function(name) {853// find parent logger854var logger = new goog.debug.Logger(name);855if (goog.debug.Logger.ENABLE_HIERARCHY) {856var lastDotIndex = name.lastIndexOf('.');857var parentName = name.substr(0, lastDotIndex);858var leafName = name.substr(lastDotIndex + 1);859var parentLogger = goog.debug.LogManager.getLogger(parentName);860861// tell the parent about the child and the child about the parent862parentLogger.addChild_(leafName, logger);863logger.setParent_(parentLogger);864}865866goog.debug.LogManager.loggers_[name] = logger;867return logger;868};869870871