Logger

An object used to log debugging messages. Loggers use a hierarchical, dot-separated naming scheme. For instance, "foo" is considered the parent of the "foo.bar" and an ancestor of "foo.bar.baz".

Each logger may be assigned a log level, which controls which level of messages will be reported to the handlers attached to this instance. If a log level is not explicitly set on a logger, it will inherit its parent.

This class should never be directly instantiated. Instead, users should obtain logger references using the getLogger() function.

Constructor

new Logger(name, opt_levelopt)

Parameters:
NameTypeAttributesDescription
namestring

the name of this logger.

opt_levelLevel<optional>

the initial level for this logger.

Methods

addHandler(handler)

Adds a handler to this logger. The handler will be invoked for each message logged with this instance, or any of its descendants.

Parameters:
NameTypeDescription
handlerfunction

the handler to add.

debug(loggable)

Logs a message at the Level.DEBUG log level.

Parameters:
NameTypeDescription
loggablestring | function

the message to log, or a function that will return the message.

fine(loggable)

Logs a message at the Level.FINE log level.

Parameters:
NameTypeDescription
loggablestring | function

the message to log, or a function that will return the message.

finer(loggable)

Logs a message at the Level.FINER log level.

Parameters:
NameTypeDescription
loggablestring | function

the message to log, or a function that will return the message.

finest(loggable)

Logs a message at the Level.FINEST log level.

Parameters:
NameTypeDescription
loggablestring | function

the message to log, or a function that will return the message.

getEffectiveLevel() → (non-null) {Level}

Returns:

the effective level for this logger.

Type: 
Level

getLevel() → {Level}

Returns:

the log level for this logger.

Type: 
Level

getName() → {string}

Returns:

the name of this logger.

Type: 
string

info(loggable)

Logs a message at the Level.INFO log level.

Parameters:
NameTypeDescription
loggablestring | function

the message to log, or a function that will return the message.

isLoggable(levelnon-null) → {boolean}

Parameters:
NameTypeDescription
levelLevel

the level to check.

Returns:

whether messages recorded at the given level are loggable by this instance.

Type: 
boolean

log(levelnon-null, loggable)

Logs a message at the given level. The message may be defined as a string or as a function that will return the message. If a function is provided, it will only be invoked if this logger's effective log level includes the given level.

Parameters:
NameTypeDescription
levelLevel

the level at which to log the message.

loggablestring | function

the message to log, or a function that will return the message.

removeHandler(handler) → {boolean}

Removes a handler from this logger.

Parameters:
NameTypeDescription
handlerfunction

the handler to remove.

Returns:

whether a handler was successfully removed.

Type: 
boolean

setLevel(level)

Parameters:
NameTypeDescription
levelLevel

the new level for this logger, or null if the logger should inherit its level from its parent logger.

severe(loggable)

Logs a message at the Level.SEVERE log level.

Parameters:
NameTypeDescription
loggablestring | function

the message to log, or a function that will return the message.

warning(loggable)

Logs a message at the Level.WARNING log level.

Parameters:
NameTypeDescription
loggablestring | function

the message to log, or a function that will return the message.