# Class goog.debug.Logger

code »

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

goog.debug.Logger ( name )

Parameters
name: `string` The name of the Logger.

## Classes

goog.debug.Logger.Level The Level class defines a set of standard logging levels that can be used to control logging output.

Show:Public Protected Private

## Instance Methods

code »addChild_ ( name, logger )

Adds a child to this logger. This is used for setting up the logger tree.

Parameters
name: `string` The leaf name of the child. logger: `goog.debug.Logger` The child logger.

code »addHandler ( handler )

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.

Parameters
handler: `Function` Handler function to add.

code »callPublish_ ( logRecord )

Calls the handlers for publish.

Parameters
logRecord: `goog.debug.LogRecord` The log record to publish.

code »config ( 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.

Parameters
msg: `goog.debug.Loggable` The message to log. opt_exception: `Error=` An exception associated with the message.

code »doLogRecord_ ( logRecord )

Logs a LogRecord.

Parameters
logRecord: `goog.debug.LogRecord` A log record to log.

code »fine ( 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.

Parameters
msg: `goog.debug.Loggable` The message to log. opt_exception: `Error=` An exception associated with the message.

code »finer ( 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.

Parameters
msg: `goog.debug.Loggable` The message to log. opt_exception: `Error=` An exception associated with the message.

code »finest ( 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.

Parameters
msg: `goog.debug.Loggable` The message to log. opt_exception: `Error=` An exception associated with the message.

code »getChildren ( ) ⇒ `!Object`

Returns the children of this logger as a map of the child name to the logger.

Returns
The map where the keys are the child leaf names and the values are the Logger objects.

code »getEffectiveLevel ( ) ⇒ `goog.debug.Logger.Level`

Returns the effective level of the logger based on its ancestors' levels.

Returns
The level.

code »getLevel ( ) ⇒ `goog.debug.Logger.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.

Returns
The level.

code »getLogRecord ( level, msg, opt_exception, opt_fnStackContext ) ⇒ `!goog.debug.LogRecord`

Creates a new log record and adds the exception (if present) to it.

Parameters
level: `goog.debug.Logger.Level` One of the level identifiers. msg: `string` The string message. opt_exception: `(Error|Object)=` An exception associated with the message. opt_fnStackContext: `Function=` A function to use as the base of the stack trace used in the log record.
Returns
A log record.

code »getName ( ) ⇒ `string`

Gets the name of this logger.

Returns
The name of this logger.

code »getParent ( ) ⇒ `goog.debug.Logger`

Returns the parent of this logger.

Returns
The parent logger or null if this is the root.

code »info ( 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.

Parameters
msg: `goog.debug.Loggable` The message to log. opt_exception: `Error=` An exception associated with the message.

code »isLoggable ( level ) ⇒ `boolean`

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.

Parameters
level: `goog.debug.Logger.Level` The level to check.
Returns
Whether the message would be logged.

code »log ( level, msg, opt_exception )

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.

Parameters
level: `goog.debug.Logger.Level` One of the level identifiers. msg: `goog.debug.Loggable` The message to log. opt_exception: `(Error|Object)=` An exception associated with the message.

code »logRecord ( logRecord )

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.

Parameters
logRecord: `goog.debug.LogRecord` A log record to log.

code »removeHandler ( handler ) ⇒ `boolean`

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.

Parameters
handler: `Function` Handler function to remove.
Returns
Whether the handler was removed.

code »setLevel ( level )

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.

Parameters
level: `goog.debug.Logger.Level` The new level.

code »setParent_ ( parent )

Sets the parent of this logger. This is used for setting up the logger tree.

Parameters
parent: `goog.debug.Logger` The parent logger.

code »severe ( 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.

Parameters
msg: `goog.debug.Loggable` The message to log. opt_exception: `Error=` An exception associated with the message.

code »shout ( msg, opt_exception )

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.

Parameters
msg: `goog.debug.Loggable` The message to log. opt_exception: `Error=` An exception associated with the message.

code »warning ( 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.

Parameters
msg: `goog.debug.Loggable` The message to log. opt_exception: `Error=` An exception associated with the message.

## Instance Properties

code »children_ : `Object`

Map of children loggers. The keys are the leaf names of the children and the values are the child loggers.

code »handlers_ : `Array.<Function>`

Handlers that are listening to this logger.

code »level_ : `goog.debug.Logger.Level`

Level that this logger only filters above. Null indicates it should inherit from the parent.

code »name_ : `string`

Name of the Logger. Generally a dot-separated namespace

code »parent_ : `goog.debug.Logger`

Parent Logger.

## Static Functions

code »goog.debug.Logger.getLogger ( name ) ⇒ `!goog.debug.Logger`
Deprecated: use goog.log instead. http://go/goog-debug-logger-deprecated

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.

Parameters
name: `string` 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.
Returns
The named logger.

code »goog.debug.Logger.logToProfilers ( msg )

Logs a message to profiling tools, if available. https://developers.google.com/web-toolkit/speedtracer/logging-api http://msdn.microsoft.com/en-us/library/dd433074(VS.85).aspx

Parameters
msg: `string` The message to log.

## Static Properties

code »goog.debug.Logger.ROOT_LOGGER_NAME : `string`
code »goog.debug.Logger.rootHandlers_ : `!Array.<Function>`
code »goog.debug.Logger.rootLevel_ : `goog.debug.Logger.Level`

## Compiler Constants

code »goog.debug.Logger.ENABLE_HIERARCHY : `boolean`