Contents
- Introduction
- log4javascript static properties/methods
- Levels
- Loggers
- Helping/disabling log4javascript Lite
Introduction
log4javascript Lite is designed to be a basic, lightweight, cross-browser logging tool. It provides functions to log messages of different severity to a pop-up window using the exactly the same syntax as log4javascript. It is designed for situations when the key requirement is just to display logging messages without needing all the features of the standard version of log4javascript.
Below is the complete list of functions and properties available in log4javascript Lite. They make up a small subset of those provided by the standard version of log4javascript. Each function is named and called identically to the equivalent function in log4javascript. Please refer to the log4javascript manual for a detailed explanation of all the concepts alluded to in this document.
log4javascript static properties/methods
Properties
- version The version number of your copy of log4javascript.
- edition The edition of your copy of log4javascript (“log4javascript_lite” in this case”).
Methods
- getDefaultLogger
Logger getDefaultLogger()
Returns the default and only logger (apart from the null logger). The default logger logs to a simple pop-up window. - getNullLogger
Logger getNullLogger()
Returns an empty logger. Useful for disabling all logging. - setEnabled
void setEnabled(Boolean enabled)
Parameters:enabled
enabled
. - isEnabled
Boolean isEnabled()
Returns true or false depending on whether logging is enabled. - setShowStackTraces
void setShowStackTraces(Boolean show)
Parameters:show
show
. By default, stack traces are not displayed. (Only works in Firefox)
Levels
Levels are available as static properties of the log4javascript.Level
object. In ascending order of severity:
log4javascript.Level.ALL
log4javascript.Level.TRACE
log4javascript.Level.DEBUG
log4javascript.Level.INFO
log4javascript.Level.WARN
log4javascript.Level.ERROR
log4javascript.Level.FATAL
log4javascript.Level.NONE
Loggers
There are only two loggers in log4javascript Lite: the default logger obtained by calling log4javascript.getDefaultLogger()
and the empty logger returned by log4javascript.getNullLogger()
.
Logger methods
- setLevel
void setLevel(Level level)
Parameters:level
level
will not be logged. Default value isALL
(unlike in log4javascript, where the default level isDEBUG
). - getLevel
Level getLevel()
Returns the level for this logger. - trace
void trace(Object message1[, Object message2, ... ][, Error exception])
Parameters:message1[, message2...]
exception
[optional]
TRACE
. - debug
void debug(Object message1[, Object message2, ... ][, Error exception])
Parameters:message1[, message2...]
exception
[optional]
DEBUG
. - info
void info(Object message1[, Object message2, ... ][, Error exception])
Parameters:message1[, message2...]
exception
[optional]
INFO
. - warn
void warn(Object message1[, Object message2, ... ][, Error exception])
Parameters:message1[, message2...]
exception
[optional]
WARN
. - error
void error(Object message1[, Object message2, ... ][, Error exception])
Parameters:message1[, message2...]
exception
[optional]
ERROR
. - fatal
void fatal(Object message1[, Object message2, ... ][, Error exception])
Parameters:message1[, message2...]
exception
[optional]
FATAL
. - isEnabledFor
Boolean isEnabledFor(Level level, Error exception)
Parameters:level
- isTraceEnabled
Boolean isTraceEnabled()
Returns whether the logger is enabled forTRACE
messages. - isDebugEnabled
Boolean isDebugEnabled()
Returns whether the logger is enabled forDEBUG
messages. - isInfoEnabled
Boolean isInfoEnabled()
Returns whether the logger is enabled forINFO
messages. - isWarnEnabled
Boolean isWarnEnabled()
Returns whether the logger is enabled forWARN
messages. - isErrorEnabled
Boolean isErrorEnabled()
Returns whether the logger is enabled forERROR
messages. - isFatalEnabled
Boolean isFatalEnabled()
Returns whether the logger is enabled forFATAL
messages.
Enabling / disabling log4javascript Lite
All logging can be enabled or disabled in log4javascript Lite in a number of ways:
- At any time, you can call
log4javascript.setEnabled(enabled)
. This will enable or disable all logging, depending on whetherenabled
is set totrue
orfalse
. - Assign your logger object a value of
log4javascript.getNullLogger()
. - Replace your copy of log4javascript_lite.js with stubs/log4javascript_lite.js, provided in the distribution. This file has a stub version of each of the functions and methods in the log4javascript Lite API and can simply be dropped in in place of the main file.