class Logger
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.
new Logger(name)
Parameters
- name
string
The name of the Logger.
Instance Methods
addHandler(handler)code »
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.
config(msg, opt_exception)code »
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
(string|function(): string)
The message to log.
- opt_exception
?Error=
An exception associated with the message.
fine(msg, opt_exception)code »
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
(string|function(): string)
The message to log.
- opt_exception
?Error=
An exception associated with the message.
finer(msg, opt_exception)code »
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
(string|function(): string)
The message to log.
- opt_exception
?Error=
An exception associated with the message.
finest(msg, opt_exception)code »
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
(string|function(): string)
The message to log.
- opt_exception
?Error=
An exception associated with the message.
getChildren()code »
Returns the children of this logger as a map of the child name to the logger.
Returns
Object
The map where the keys are the child leaf names and the
values are the Logger objects.
getEffectiveLevel()code »
Returns the effective level of the logger based on its ancestors' levels.
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.
getLogRecord(level, msg, opt_exception)code »
Creates a new log record and adds the exception (if present) to it.
Gets the name of this logger.
Returns
string
The name of this logger.
Returns the parent of this logger.
info(msg, opt_exception)code »
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
(string|function(): string)
The message to log.
- opt_exception
?Error=
An exception associated with the message.
isLoggable(level)code »
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.
Returns
boolean
Whether the message would be logged.
log(level, msg, opt_exception)code »
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.
logRecord(logRecord)code »
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.
removeHandler(handler)code »
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
boolean
Whether the handler was removed.
setLevel(level)code »
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.
severe(msg, opt_exception)code »
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
(string|function(): string)
The message to log.
- opt_exception
?Error=
An exception associated with the message.
shout(msg, opt_exception)code »
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
(string|function(): string)
The message to log.
- opt_exception
?Error=
An exception associated with the message.
warning(msg, opt_exception)code »
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
(string|function(): string)
The message to log.
- opt_exception
?Error=
An exception associated with the message.
Static Functions
Logger.getLogger(name)code »
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.
- Deprecated
use goog.log instead. http://go/goog-debug-logger-deprecated
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.
Logger.logToProfilers(msg)code »
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
Compiler Constants
- Logger.ENABLE_HIERARCHY
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.