blob: defac9c59f2beb00b8ed87031f2c7a92d7eaf6f7 [file] [log] [blame]
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>log4javascript 1.4 manual</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Tim Down - tim@log4javascript.org" />
<meta name="description" content="log4javascript, a logging framework for JavaScript based on log4j" />
<meta name="robots" content="all" />
<link rel="stylesheet" type="text/css" media="screen,print" href="../main.css" title="Default" />
</head>
<body>
<div id="container" class="nonav">
<div id="header">
<h1><a href="index.html">log4javascript</a></h1>
</div>
<div id="content">
<div id="nav">
<a class="navitem" href="../index.html">home</a>
| <a class="navitem" href="http://sourceforge.net/projects/log4javascript" target="_blank" title="Download (opens in new window)">download</a>
| <a class="navitem" href="index.html">docs</a>
| <a class="navitem" href="quickstart.html">quick start</a>
| <a class="navitem" href="../demos/index.html">demos</a>
| <a class="navitem" href="http://log4javascript.org" target="_blank">website</a>
| <a class="navitem" href="http://www.timdown.co.uk" target="_blank">timdown.co.uk</a>
</div>
<h1>log4javascript 1.4 manual</h1>
<h2>Contents</h2>
<ul>
<li><a href="#intro">Introduction</a></li>
<li><a href="#noteaboutlog4javascript">Note about the log4javascript object</a></li>
<li>
<a href="#loggersappenderslayoutslevels">Loggers, appenders, layouts and levels</a>
<ul>
<li><a href="#configuration">Configuring appenders</a></li>
<li><a href="#loggersappenderslayoutslevelsexample">Example</a></li>
</ul>
</li>
<li><a href="#log4javascript">log4javascript static properties/methods</a></li>
<li><a href="#levels">Levels</a></li>
<li><a href="#loggers">Loggers</a></li>
<li>
<a href="#appenders">Appenders</a>
<ul>
<li><a href="#appender">Appender</a></li>
<li><a href="#alertappender">AlertAppender</a></li>
<li><a href="#ajaxappender">AjaxAppender</a></li>
<li><a href="#popupappender">PopUpAppender</a></li>
<li><a href="#inpageappender">InPageAppender</a></li>
<li><a href="#browserconsoleappender">BrowserConsoleAppender</a></li>
</ul>
</li>
<li>
<a href="#layouts">Layouts</a>
<ul>
<li><a href="#layout">Layout</a></li>
<li><a href="#nulllayout">NullLayout</a></li>
<li><a href="#simplelayout">SimpleLayout</a></li>
<li><a href="#patternlayout">PatternLayout</a></li>
<li><a href="#xmllayout">XmlLayout</a></li>
<li><a href="#jsonlayout">JsonLayout</a></li>
<li><a href="#httppostdatalayout">HttpPostDataLayout</a></li>
</ul>
</li>
<li><a href="#enabling">Enabling / disabling log4javascript</a></li>
<li>
<a href="#errorhandling">log4javascript error handling</a>
<ul>
<li><a href="#loglog">LogLog</a></li>
</ul>
</li>
<li><a href="#differences">Differences between log4javascript and log4j</a></li>
</ul>
<div id="intro">
<h2>Introduction</h2>
<p>
Anyone who has done a reasonable amount of JavaScript development will be
familiar with <code>alert</code> as a means of debugging. For
a small script, it works fine. But for anything of greater complexity than,
say, a rollover script its shortcomings become apparent. The most obvious problem
is the endless clicking of 'OK'. Another problem is that for a page
heavily reliant on events generated from user actions, alerts
can actually alter the way the page behaves. One final problem is infinite loops:
without alerts, the browser will notice that the script has messed
up and will offer the user the chance to stop the script running. With an
alert inside an infinite loop, you're forced to kill the browser.
</p>
<p>
At the other end of the scale there is
<a href="http://www.mozilla.org/projects/venkman/" target="_blank">Venkman</a>,
a full-on JavaScript debugger for Mozilla-based browsers such as Firefox. Here
I have to confess that I simply have not put in the time to learn how to make
it work well for me and I suspect I am not alone.
</p>
<p>
Nowadays, easily the best option for day-to-day JavaScript development is the brilliant
<a href="http://www.getfirebug.com" title="Firebug home page (opens in new window)"
target="_blank">Firebug</a>, a Firefox plugin with built-in debugger, console, logging,
and profiler. It's a seriously impressive tool but by its very nature as a Firefox
plugin can only be used in one of the typical target browsers for mainstream web
development.
</p>
<p>
log4javascript was originally written as a cross-browser tool to ease the pain of JavaScript
debugging without the time investment required to use a debugger effectively. It requires
only a JavaScript include and one line of code to initialize with default settings.
Having for several years used log4j and its .NET port log4net, it was natural for me to
base it on log4j.
</p>
<p>
log4javascript is by no means the only JavaScript logging framework out there.
It is not even the only JavaScript implementation of log4j. It turns out the name
log4javascript is used by another JavaScript logging framework, and that the name log4js is
used by at least two other pieces of software; this version of log4javascript is unrelated
to any of those.
</p>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="noteaboutlog4javascript">
<h2>Note about the log4javascript object</h2>
<p>
All of log4javascript's instantiable classes are accessible via the log4javascript object, which
acts as a namespace. Therefore references to all class names must be preceded with "log4javascript.".
For example:
</p>
<p>
<code>var popUpAppender = new log4javascript.PopUpAppender();</code>
</p>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="loggersappenderslayoutslevels">
<h2>Loggers, Appenders, Layouts and Levels</h2>
<p>
A <em>logger</em> in log4javascript is the object on which log calls are
made. A logger may be assigned zero or more <em>appenders</em>.
An appender is an object that actually does the logging: for example,
a <code><a href="#popupappender">PopUpAppender</a></code> logs messages to
a pop-up console window while an <code><a href="#ajaxappender">AjaxAppender</a></code>
uses HTTP to send log messages back to the server. Each appender is assigned
a <em>layout</em>, which is responsible for formatting log messages that
are passed to an appender.
</p>
<p>
Every log message has a <em>level</em>. This is the severity of the message.
Available levels are <code>TRACE</code>, <code>DEBUG</code>, <code>INFO</code>,
<code>WARN</code>, <code>ERROR</code> and <code>FATAL</code> - these correspond to
the logging methods <code>trace</code>, <code>debug</code>, <code>info</code>,
<code>warn</code>, <code>error</code> and <code>fatal</code> of <code>Logger</code>.
Levels are ordered as follows: <code>TRACE</code> &lt; <code>DEBUG</code> &lt;
<code>INFO</code> &lt; <code>WARN</code> &lt; <code>ERROR</code> &lt;
<code>FATAL</code>. This means the <code>FATAL</code> is the most severe and
<code>TRACE</code> the least. Also included are levels called <code>ALL</code>
and <code>OFF</code> intended to enable or disable all logging respectively.
</p>
<p>
Both loggers and appenders also have threshold levels (by default, <code>DEBUG</code>
for loggers and <code>ALL</code> for appenders).
Setting a level to either a logger or an appender disables log messages of severity
lower than that level. For instance, if a level of <code>INFO</code> is set on a
logger then only log messages of severity <code>INFO</code> or greater will be logged,
meaning <code>DEBUG</code> and <code>TRACE</code> messages will not be logged. If the
same logger had two appenders, one of level <code>DEBUG</code> and one of level
<code>WARN</code> then the first appender will still only log messages of
<code>INFO</code> or greater while the second appender will only log messages of level
<code>WARN</code> or greater.
</p>
<p>
This allows the developer fine control over which messages get logged where.
</p>
<div id="configuration">
<h3>Configuring appenders</h3>
<p>
From version 1.4, <strong>configuring appenders is only possible via configuration
methods</strong>. As the number of configuration options increases it becomes increasingly
undesirable to use constructor parameters, so support for it has been dropped.
</p>
</div>
<div id="loggersappenderslayoutslevelsexample">
<h3>Example</h3>
<p>
<strong>NB.</strong> The Ajax side of this example relies on having
server-side processing in place.
</p>
<p>
First, log4javascript is initialized, and a logger (actually the
anonymous logger) is assigned to a variable called <code>log</code>:
</p>
<pre class="code">
&lt;script type="text/javascript" src="log4javascript.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
//&lt;![CDATA[
var log = log4javascript.getLogger();
</pre>
<p>
<code>log</code> does not yet have any appenders, so a call to <code>log.debug()</code>
will do nothing as yet. For this example we will use a
<code><a href="#popupappender">PopUpAppender</a></code> for debugging purposes.
Since the lifespan of the messages displayed in the pop-up is only going to be the
same as that of the window, a <code><a href="#patternlayout">PatternLayout</a></code>
is used that displays the time of the message and not the date (note that this is
also true of PopUpAppender's default layout). The format of the string passed into
PatternLayout is explained <a href="#patternlayout">below</a>.
</p>
<pre class="code">
var popUpAppender = new log4javascript.PopUpAppender();
var popUpLayout = new log4javascript.PatternLayout("%d{HH:mm:ss} %-5p - %m%n");
popUpAppender.setLayout(popUpLayout);
log.addAppender(popUpAppender);
</pre>
<p>
Suppose that we also want to send log messages to the server, but limited to
error messages only. To achieve this we use an
<code><a href="#ajaxappender">AjaxAppender</a></code>. Note that if no layout is
specified then for convenience a default layout is used; in the case of
AjaxAppender, that is <code><a href="#httppostdatalayout">HttpPostDataLayout</a></code>,
which formats log messages as a standard HTTP POST string from which a simple
server-side script (not provided with log4javascript) will be able to extract
posted parameters. This is fine for our purposes:
</p>
<pre class="code">
var ajaxAppender = new log4javascript.AjaxAppender("myloggingservlet.do");
ajaxAppender.setThreshold(log4javascript.Level.<code>ERROR</code>);
log.addAppender(ajaxAppender);
</pre>
<p>
Finally, some test log messages and the closing script tag:
</p>
<pre class="code">
log.debug("Debugging message (appears in pop-up)");
log.error("Error message (appears in pop-up and in server log)");
//]]&gt;
&lt;/script&gt;
</pre>
<p>
The full script:
</p>
<pre class="code">
&lt;script type="text/javascript" src="log4javascript.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
//&lt;![CDATA[
var log = log4javascript.getLogger();
var popUpAppender = new log4javascript.PopUpAppender();
var popUpLayout = new log4javascript.PatternLayout("%d{HH:mm:ss} %-5p - %m%n");
popUpAppender.setLayout(popUpLayout);
log.addAppender(popUpAppender);
var ajaxAppender = new log4javascript.AjaxAppender("myloggingservlet.do");
ajaxAppender.setThreshold(log4javascript.Level.ERROR);
log.addAppender(ajaxAppender);
log.debug("Debugging message (appears in pop-up)");
log.error("Error message (appears in pop-up and in server log)");
//]]&gt;
&lt;/script&gt;
</pre>
<p>
<a href="../examples/example_manual.html" title="View example (opens in new window)"
target="_blank">See this example in action</a> (opens in new window)
</p>
</div>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="log4javascript">
<h2>log4javascript static properties/methods</h2>
<h4>Properties</h4>
<ul class="propertieslist">
<li class="property">
<div class="name">version</div>
<div class="summary">
The version number of your copy of log4javascript.
</div>
</li>
<li class="property">
<div class="name">edition</div>
<div class="summary">
The edition of your copy of log4javascript.
</div>
</li>
<li class="property">
<div class="name">logLog</div>
<div class="summary">
log4javascript's internal logging object. <a href="#loglog">See below for more details</a>.
</div>
</li>
</ul>
<h4>Methods</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">getLogger</div>
<div class="methodsignature"><code>Logger <strong>getLogger</strong>([String <em>loggerName</em>])</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">loggerName</code>
[<em>optional</em>]
</li>
</ul>
<div class="summary">
<p>
Returns a logger with the specified name, creating it if a logger with that name does not
already exist. If no name is specified, a logger is returned with name <code>[anonymous]</code>, and
subsequent calls to <code>getLogger()</code> (with no logger name specified) will return
this same logger object.
</p>
<p>
Note that the names <code>[anonymous]</code>, <code>[default]</code>, <code>[null]</code>
and <code>root</code> are reserved for
the anonymous logger, default logger, null logger and root logger respectively.
</p>
</div>
</li>
<li class="method">
<div class="name">getDefaultLogger</div>
<div class="methodsignature"><code>Logger <strong>getDefaultLogger</strong>()</code></div>
<div class="summary">
Convenience method that returns the default logger. The default logger
has a single appender: a <code><a href="#popupappender">PopUpAppender</a></code>
with the default layout, width and height, and with <code>focusPopUp</code> set to false
and <code>lazyInit</code>, <code>useOldPopUp</code> and
<code>complainAboutPopUpBlocking</code> all set to true.
</div>
</li>
<li class="method">
<div class="name">getNullLogger</div>
<div class="methodsignature"><code>Logger <strong>getNullLogger</strong>()</code></div>
<div class="summary">
Returns an empty logger with no appenders. Useful for disabling all logging.
</div>
</li>
<li class="method">
<div class="name">getRootLogger</div>
<div class="methodsignature"><code>Logger <strong>getRootLogger</strong>()</code></div>
<div class="summary">
Returns the root logger from which all other loggers derive.
</div>
</li>
<li class="method">
<div class="name">resetConfiguration</div>
<div class="methodsignature"><code>void <strong>resetConfiguration</strong>()</code></div>
<div class="summary">
Resets the all loggers to their default level.
</div>
</li>
<li class="method">
<div class="name">setEnabled</div>
<div class="methodsignature"><code>void <strong>setEnabled</strong>(Boolean <em>enabled</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">enabled</code>
</li>
</ul>
<div class="summary">
Enables or disables all logging, depending on <code>enabled</code>.
</div>
</li>
<li class="method">
<div class="name">isEnabled</div>
<div class="methodsignature"><code>Boolean <strong>isEnabled</strong>()</code></div>
<div class="summary">
Returns true or false depending on whether logging is enabled.
</div>
</li>
<li class="method" id="log4javascriptaddeventlistener">
<div class="name">addEventListener</div>
<div class="methodsignature"><code>void <strong>addEventListener</strong>(String <em>eventType</em>, Function <em>listener</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">eventType</code>
</li>
<li class="param">
<code class="paramname">listener</code>
</li>
</ul>
<div class="summary">
<p>
Adds a function to be called when an event of the type specified occurs in log4javascript.
Supported event types are <code>load</code> (occurs once the page has loaded) and
<code>error</code>.
</p>
<p>
Each listener is pased three paramaters:
</p>
<ul>
<li><code>sender</code>. The object that raised the event (i.e. the log4javascript object);</li>
<li><code>eventType</code>. The type of the event;</li>
<li>
<code>eventArgs</code>. An object containing of event-specific arguments. For the <code>error</code> event,
this is an object with properties <code>message</code> and <code>exception</code>. For the <code>load</code>
event this is an empty object.
</li>
</ul>
</div>
</li>
<li class="method">
<div class="name">removeEventListener</div>
<div class="methodsignature"><code>void <strong>removeEventListener</strong>(String <em>eventType</em>, Function <em>listener</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">eventType</code>
</li>
<li class="param">
<code class="paramname">listener</code>
</li>
</ul>
<div class="summary">
Removes the event listener function supplied for the event of the type specified.
</div>
</li>
<li class="method">
<div class="name">dispatchEvent</div>
<div class="methodsignature"><code>void <strong>dispatchEvent</strong>(String <em>eventType</em>, Object <em>eventArgs</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">eventType</code>
</li>
<li class="param">
<code class="paramname">eventArgs</code>
</li>
</ul>
<div class="summary">
Raises an event of type <code>eventType</code> on the <code>log4javascript</code> object.
Each of the listeners for this type of event (registered via <code>addEventListener</code>)
is called and passed <code>eventArgs</code> as the third parameter.
</div>
</li>
<li class="method">
<div class="name">setEventTypes</div>
<div class="methodsignature"><code>void <strong>setEventTypes</strong>(Array <em>eventTypes</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">eventTypes</code>
</li>
</ul>
<div class="summary">
Used internally to specify the types of events that the <code>log4javascript</code> object can raise.
</div>
</li>
<li class="method">
<div class="name">setShowStackTraces</div>
<div class="methodsignature"><code>void <strong>setShowStackTraces</strong>(Boolean <em>show</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">show</code>
</li>
</ul>
<div class="summary">
Enables or disables displaying of error stack traces, depending on <code>show</code>.
By default, stack traces are not displayed. (Only works in Firefox)
</div>
</li>
<li class="method">
<div class="name">evalInScope</div>
<div class="methodsignature"><code>Object <strong>evalInScope</strong>(String <em>expr</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">expr</code>
</li>
</ul>
<div class="summary">
This evaluates the given expression in the log4javascript scope, thus allowing
scripts to access internal log4javascript variables and functions. This was written
for the purposes of automated testing but could be used by custom extensions to
log4javascript.
</div>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="levels">
<h2>Levels</h2>
<p>
Levels are available as static properties of the <code>log4javascript.Level</code>
object. In ascending order of severity:
</p>
<ol>
<li><code>log4javascript.Level.ALL</code></li>
<li><code>log4javascript.Level.TRACE</code></li>
<li><code>log4javascript.Level.DEBUG</code></li>
<li><code>log4javascript.Level.INFO</code></li>
<li><code>log4javascript.Level.WARN</code></li>
<li><code>log4javascript.Level.ERROR</code></li>
<li><code>log4javascript.Level.FATAL</code></li>
<li><code>log4javascript.Level.OFF</code></li>
</ol>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="loggers">
<h2>Loggers</h2>
<p>
It is possible to have multiple loggers in log4javascript. For example, you
may wish to have a logger for debugging purposes that logs messages to a
pop-up window and a separate logger that reports any client-side application
errors to the server via Ajax.
</p>
<div id="loggerhierarchy">
<h3>Logger hierarchy and appender additivity</h3>
<p>
From version 1.4, log4javascript has hierarchical loggers, implemented in the same way
as log4j. In summary, you specify a logger's parent logger by means of a dot between the
parent logger name and the child logger name. Therefore the logger <code>tim.app.security</code>
inherits from <code>tim.app</code>, which in turn inherits from <code>tim</code> which,
finally, inherits from the root logger.
</p>
<p>
What inheritance means for a logger is that in the absence of a threshold level set
specifically on the logger it inherits its level from its parent; also, a logger inherits
all its parent's appenders (this is known as <em>appender additivity</em> in log4j. This
behaviour can be enabled or disabled via <code>setAdditivity()</code>. See below). In the
above example, if the root logger has a level of <code>DEBUG</code> and one appender,
each of the loggers <code>tim.app.security</code>, <code>tim.app</code> and <code>tim</code> would
inherit the root level's appender. If, say, <code>tim.app</code>'s threshold level was set
to <code>WARN</code>, <code>tim</code>'s effective level would remain at <code>DEBUG</code>
(inherited from the root logger) while <code>tim.app.security</code>'s effective level would
be <code>WARN</code>, inherited from <code>tim.app</code>. The important thing to note is
that appenders accumulate down the logger hierarchy while levels are simply inherited from
the nearest ancestor with a threshold level set.
</p>
<p>
For a detailed explanation of the logger hierarchy, see the
<a href="http://logging.apache.org/log4j/docs/manual.html" target="_blank"
title="Log4j manual (opens in new window)">log4j manual</a>.
</p>
</div>
<p><strong>Notes</strong></p>
<ul>
<li>
It is not possible to instantiate loggers directly. Instead you must use
one of the methods of the <code>log4javascript</code> object: <code>getLogger</code>,
<code>getRootLogger</code>, <code>getDefaultLogger</code> or <code>getNullLogger</code>.
</li>
</ul>
<h4>Logger methods</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">addAppender</div>
<div class="methodsignature"><code>void <strong>addAppender</strong>(Appender <em>appender</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">appender</code>
</li>
</ul>
<div class="summary">
Adds the given appender.
</div>
</li>
<li class="method">
<div class="name">removeAppender</div>
<div class="methodsignature"><code>void <strong>removeAppender</strong>(Appender <em>appender</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">appender</code>
</li>
</ul>
<div class="summary">
Removes the given appender.
</div>
</li>
<li class="method">
<div class="name">removeAllAppenders</div>
<div class="methodsignature"><code>void <strong>removeAllAppenders</strong>()</code></div>
<div class="summary">
Clears all appenders for the current logger.
</div>
</li>
<li class="method">
<div class="name">setLevel</div>
<div class="methodsignature"><code>void <strong>setLevel</strong>(Level <em>level</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">level</code>
</li>
</ul>
<div class="summary">
Sets the level. Log messages of a lower level than <code>level</code> will not be logged.
Default value is <code>DEBUG</code>.
</div>
</li>
<li class="method">
<div class="name">getLevel</div>
<div class="methodsignature"><code>Level <strong>getLevel</strong>()</code></div>
<div class="summary">
Returns the level explicitly set for this logger or <code>null</code> if none has been set.
</div>
</li>
<li class="method">
<div class="name">getEffectiveLevel</div>
<div class="methodsignature"><code>Level <strong>getEffectiveLevel</strong>()</code></div>
<div class="summary">
Returns the level at which the logger is operating. This is either the level explicitly
set on the logger or, if no level has been set, the effective level of the logger's parent.
</div>
</li>
<li class="method">
<div class="name">setAdditivity</div>
<div class="methodsignature"><code>void <strong>setAdditivity</strong>(Boolean <em>additivity</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">additivity</code>
</li>
</ul>
<div class="summary">
<p>
Sets whether appender additivity is enabled (the default) or disabled. If set to false, this
particular logger will not inherit any appenders form its ancestors. Any descendant of this
logger, however, will inherit from its ancestors as normal, unless its own additivity is
explicitly set to false.
</p>
<p>
Default value is <code>true</code>.
</p>
</div>
</li>
<li class="method">
<div class="name">getAdditivity</div>
<div class="methodsignature"><code>Level <strong>getLevel</strong>()</code></div>
<div class="summary">
Returns whether additivity is enabled for this logger.
</div>
</li>
<li class="method">
<div class="name">log</div>
<div class="methodsignature"><code>void <strong>log</strong>(Level <em>level</em>, Object <em>params</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">level</code>
</li>
<li class="param">
<code class="paramname">params</code>
</li>
</ul>
<div class="summary">
Generic logging method used by wrapper methods such as <code>debug</code>,
<code>error</code> etc.
</div>
<p><strong>Notes</strong></p>
<ul>
<li>
The signature of this method has changed in 1.4.
</li>
</ul>
</li>
<li class="method">
<div class="name">trace</div>
<div class="methodsignature"><code>void <strong>trace</strong>(Object <em>message1</em>[, Object <em>message2</em>, ... ][, Error <em>exception</em>])</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">message1[, message2...]</code>
</li>
<li class="param">
<code class="paramname">exception</code>
[<em>optional</em>]
</li>
</ul>
<div class="summary">
Logs one or more messages and optionally an error at level <code>TRACE</code>.
</div>
<p><strong>Notes</strong></p>
<ul>
<li>
Logging of multiple messages in one call is new in 1.4.
</li>
</ul>
</li>
<li class="method">
<div class="name">debug</div>
<div class="methodsignature"><code>void <strong>debug</strong>(Object <em>message1</em>[, Object <em>message2</em>, ... ][, Error <em>exception</em>])</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">message1[, message2...]</code>
</li>
<li class="param">
<code class="paramname">exception</code>
[<em>optional</em>]
</li>
</ul>
<div class="summary">
Logs one or more messages and optionally an error at level <code>DEBUG</code>.
</div>
<p><strong>Notes</strong></p>
<ul>
<li>
Logging of multiple messages in one call is new in 1.4.
</li>
</ul>
</li>
<li class="method">
<div class="name">info</div>
<div class="methodsignature"><code>void <strong>info</strong>(Object <em>message1</em>[, Object <em>message2</em>, ... ][, Error <em>exception</em>])</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">message1[, message2...]</code>
</li>
<li class="param">
<code class="paramname">exception</code>
[<em>optional</em>]
</li>
</ul>
<div class="summary">
Logs one or more messages and optionally an error at level <code>INFO</code>.
</div>
<p><strong>Notes</strong></p>
<ul>
<li>
Logging of multiple messages in one call is new in 1.4.
</li>
</ul>
</li>
<li class="method">
<div class="name">warn</div>
<div class="methodsignature"><code>void <strong>warn</strong>(Object <em>message1</em>[, Object <em>message2</em>, ... ][, Error <em>exception</em>])</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">message1[, message2...]</code>
</li>
<li class="param">
<code class="paramname">exception</code>
[<em>optional</em>]
</li>
</ul>
<div class="summary">
Logs one or more messages and optionally an error at level <code>WARN</code>.
</div>
<p><strong>Notes</strong></p>
<ul>
<li>
Logging of multiple messages in one call is new in 1.4.
</li>
</ul>
</li>
<li class="method">
<div class="name">error</div>
<div class="methodsignature"><code>void <strong>error</strong>(Object <em>message1</em>[, Object <em>message2</em>, ... ][, Error <em>exception</em>])</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">message1[, message2...]</code>
</li>
<li class="param">
<code class="paramname">exception</code>
[<em>optional</em>]
</li>
</ul>
<div class="summary">
Logs one or more messages and optionally an error at level <code>ERROR</code>.
</div>
<p><strong>Notes</strong></p>
<ul>
<li>
Logging of multiple messages in one call is new in 1.4.
</li>
</ul>
</li>
<li class="method">
<div class="name">fatal</div>
<div class="methodsignature"><code>void <strong>fatal</strong>(Object <em>message1</em>[, Object <em>message2</em>, ... ][, Error <em>exception</em>])</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">message1[, message2...]</code>
</li>
<li class="param">
<code class="paramname">exception</code>
[<em>optional</em>]
</li>
</ul>
<div class="summary">
Logs one or more messages and optionally an error at level <code>FATAL</code>.
</div>
<p><strong>Notes</strong></p>
<ul>
<li>
Logging of multiple messages in one call is new in 1.4.
</li>
</ul>
</li>
<li class="method">
<div class="name">isEnabledFor</div>
<div class="methodsignature"><code>Boolean <strong>isEnabledFor</strong>(Level <em>level</em>, Error <em>exception</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">level</code>
</li>
</ul>
<div class="summary">
Returns whether the logger is enabled for the specified level.
</div>
</li>
<li class="method">
<div class="name">isTraceEnabled</div>
<div class="methodsignature"><code>Boolean <strong>isTraceEnabled</strong>()</code></div>
<div class="summary">
Returns whether the logger is enabled for <code>TRACE</code> messages.
</div>
</li>
<li class="method">
<div class="name">isDebugEnabled</div>
<div class="methodsignature"><code>Boolean <strong>isDebugEnabled</strong>()</code></div>
<div class="summary">
Returns whether the logger is enabled for <code>DEBUG</code> messages.
</div>
</li>
<li class="method">
<div class="name">isInfoEnabled</div>
<div class="methodsignature"><code>Boolean <strong>isInfoEnabled</strong>()</code></div>
<div class="summary">
Returns whether the logger is enabled for <code>INFO</code> messages.
</div>
</li>
<li class="method">
<div class="name">isWarnEnabled</div>
<div class="methodsignature"><code>Boolean <strong>isWarnEnabled</strong>()</code></div>
<div class="summary">
Returns whether the logger is enabled for <code>WARN</code> messages.
</div>
</li>
<li class="method">
<div class="name">isErrorEnabled</div>
<div class="methodsignature"><code>Boolean <strong>isErrorEnabled</strong>()</code></div>
<div class="summary">
Returns whether the logger is enabled for <code>ERROR</code> messages.
</div>
</li>
<li class="method">
<div class="name">isFatalEnabled</div>
<div class="methodsignature"><code>Boolean <strong>isFatalEnabled</strong>()</code></div>
<div class="summary">
Returns whether the logger is enabled for <code>FATAL</code> messages.
</div>
</li>
<li class="method">
<div class="name">group</div>
<div class="methodsignature"><code>void <strong>group</strong>(String <em>name</em>, Boolean <em>initiallyExpanded</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">name</code>
</li>
<li class="param">
<code class="paramname">initiallyExpanded</code>
[<em>optional</em>]
</li>
</ul>
<div class="summary">
Starts a new group of log messages. In appenders that support grouping (currently
<code><a href="#popupappender">PopUpAppender</a></code> and
<code><a href="#inpageappender">InPageAppender</a></code>), a group appears as an expandable
section in the console, labelled with the <code>name</code> specified.
Specifying <code>initiallyExpanded</code> determines whether the
group starts off expanded (the default is <code>true</code>). Groups may be nested.
</div>
</li>
<li class="method">
<div class="name">groupEnd</div>
<div class="methodsignature"><code>void <strong>groupEnd</strong>()</code></div>
<div class="summary">
Ends the current group. If there is no group then this function has no effect.
</div>
</li>
<li class="method">
<div class="name">time</div>
<div class="methodsignature"><code>void <strong>time</strong>(String <em>name</em>, Level <em>level</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">name</code>
</li>
<li class="param">
<code class="paramname">level</code>
[<em>optional</em>]
</li>
</ul>
<div class="summary">
Starts a timer with name <code>name</code>. When the timer is ended with a
call to <code>timeEnd</code> using the same name, the amount of time that
has elapsed in milliseconds since the timer was started is logged at level
<code>level</code>. If not level is supplied, the level defaults to <code>INFO</code>.
</div>
</li>
<li class="method">
<div class="name">timeEnd</div>
<div class="methodsignature"><code>void <strong>timeEnd</strong>(String <em>name</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">name</code>
</li>
</ul>
<div class="summary">
Ends the timer with name <code>name</code> and logs the time elapsed.
</div>
</li>
<li class="method">
<div class="name">assert</div>
<div class="methodsignature"><code>void <strong>assert</strong>(Object <em>expr</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">expr</code>
</li>
</ul>
<div class="summary">
Asserts the given expression is <code>true</code> or evaluates to <code>true</code>.
If so, nothing is logged. If not, an error is logged at the <code>ERROR</code> level.
</div>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="appenders">
<h2>Appenders</h2>
<div id="appender">
<h3>Appender</h3>
<p>
There are methods common to all appenders, as listed below.
</p>
<h4>Methods</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">doAppend</div>
<div class="methodsignature"><code>void <strong>doAppend</strong>(LoggingEvent <em>loggingEvent</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">loggingEvent</code>
</li>
</ul>
<div class="summary">
<p>
Checks the logging event's level is at least as severe as the appender's
threshold and calls the appender's <code>append</code> method if so.
</p>
<p>
This method should not in general be used directly or overridden.
</p>
</div>
</li>
<li class="method">
<div class="name">append</div>
<div class="methodsignature"><code>void <strong>append</strong>(LoggingEvent <em>loggingEvent</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">loggingEvent</code>
</li>
</ul>
<div class="summary">
Appender-specific method to append a log message. Every appender object should implement
this method.
</div>
</li>
<li class="method">
<div class="name">setLayout</div>
<div class="methodsignature"><code>void <strong>setLayout</strong>(Layout <em>layout</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">layout</code>
</li>
</ul>
<div class="summary">
Sets the appender's layout.
</div>
</li>
<li class="method">
<div class="name">getLayout</div>
<div class="methodsignature"><code>Layout <strong>getLayout</strong>()</code></div>
<div class="summary">
Returns the appender's layout.
</div>
</li>
<li class="method">
<div class="name">setThreshold</div>
<div class="methodsignature"><code>void <strong>setThreshold</strong>(Level <em>level</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">level</code>
</li>
</ul>
<div class="summary">
Sets the appender's threshold. Log messages of level less severe than this
threshold will not be logged.
</div>
</li>
<li class="method">
<div class="name">getThreshold</div>
<div class="methodsignature"><code>Level <strong>getThreshold</strong>()</code></div>
<div class="summary">
Returns the appender's threshold.
</div>
</li>
<li class="method">
<div class="name">toString</div>
<div class="methodsignature"><code>string <strong>toString</strong>()</code></div>
<div class="summary">
Returns a string representation of the appender. Every appender object should implement
this method.
</div>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="alertappender">
<h3>AlertAppender</h3>
<p class="editions">Editions: <strong>Standard</strong></p>
<p>
Displays a log message as a JavaScript alert.
</p>
<h4>Constructor</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">AlertAppender</div>
<div class="methodsignature"><code><strong>AlertAppender</strong>()</code></div>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="ajaxappender">
<h3>AjaxAppender</h3>
<p class="editions">Editions: <strong>Standard, Production</strong></p>
<p>
A flexible appender that asynchronously sends log messages to a server via HTTP
(Ajax, if you insist, though the 'x' of Ajax only comes into play in any form if you use an
<code><a href="#xmllayout">XmlLayout</a></code>).
</p>
<p>
The default configuration is to send each log message as a separate HTTP post
request to the server using an <code><a href="#httppostdatalayout">HttpPostDataLayout</a></code>,
without waiting for a response before sending any subsequent requests. However,
an <code>AjaxAppender</code> may be configured to do any one of or combinations of the following:
</p>
<ul>
<li>
send log messages in batches (if the selected layout supports it - particularly suited
to <code>AjaxAppender</code> are <code><a href="#jsonlayout">JsonLayout</a></code> and
<code><a href="#xmllayout">XmlLayout</a></code>, both of which allow batching);
</li>
<li>
wait for a response from a previous request before sending the next log message / batch
of messages;
</li>
<li>
send all queued log messages at timed intervals.
</li>
</ul>
<p><strong>Notes</strong></p>
<ul>
<li>
AjaxAppender relies on the <code>XMLHttpRequest</code> object. It also requires
the presence of correctly implemented <code>setRequestHeader</code> method on
this object, which rules out Opera prior to version 8.01. If your browser does not
support the necessary objects then one alert will display to explain why it
doesn't work, after which the appender will silently switch off.
</li>
<li>
In AjaxAppender only, <code>setLayout</code> may not be called after the first
message has been logged.
</li>
<li>
The default layout is <code><a href="#httppostdatalayout">HttpPostDataLayout</a></code>.
</li>
<li>
From version 1.4, log message data is always sent as one or more name/value pairs.
In the case of <code><a href="#httppostdatalayout">HttpPostDataLayout</a></code>, data
is sent the same as in previous versions. For other layouts such as
<code><a href="#jsonlayout">JsonLayout</a></code> and
<code><a href="#xmllayout">XmlLayout</a></code>, the formatted log message is posted as
the value of a parameter called <code>data</code>, though this may be changed via
<code>setPostVarName</code>.
</li>
<li>
From version 1.4, log message timestamps are sent as standard JavaScript times, i.e.
the number of milliseconds since 00:00:00 UTC on January 1, 1970.
</li>
<li>
<p>
Also from version 1.4, any outstanding log messages may optionally be sent when the
main page unloads (i.e. user follows a link, closes the window or refreshes the
page). This behaviour may be enabled using <code>setSendAllOnUnload</code>; see
below.
</p>
<p>
This behaviour is dependent on <code>window.onbeforeunload</code>; unfortunately,
Opera does not always raise this event, so this feature does not work reliably in
Opera.
</p>
</li>
</ul>
<h4>Constructor</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">AjaxAppender</div>
<div class="methodsignature">
<code><strong>AjaxAppender</strong>(String <em>url</em>)</code>
</div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">url</code>
<div>
The URL to which log messages should be sent. Note that this is subject
to the usual Ajax restrictions: the URL should be in the same domain as that
of the page making the request.
</div>
</li>
</ul>
</li>
</ul>
<h4>Methods</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">setSendAllOnUnload</div>
<div class="methodsignature"><code>void <strong>setSendAllOnUnload</strong>(Boolean <em>sendAllOnUnload</em>)</code></div>
<div class="summary">
<p>
[<em>not available after first message logged</em>]
</p>
<p>
Whether to send all remaining unsent log messages to the server when the page
unloads.
</p>
<p>
Since version 1.4.3, the default value is <code>false</code>. Previously the
default was <code>true</code>.
</p>
<p><strong>Notes</strong></p>
<ul>
<li>
This feature was found not to work prior to version 1.4.3 in WebKit
browsers (e.g. Google Chrome, Safari). As a result, a workaround was
implemented in 1.4.3 which has the unfortunate side effect of popping up a
confirmation dialog to the user if there are any log messages to send when
the page unloads. As a result, this feature is now obtrusive for the user
and is therefore disabled by default.
</li>
<li>
This feature does not work in any version of Opera.
</li>
</ul>
</div>
</li>
<li class="method">
<div class="name">isSendAllOnUnload</div>
<div class="methodsignature"><code>Boolean <strong>isSendAllOnUnload</strong>()</code></div>
<div class="summary">
Returns whether all remaining unsent log messages are sent to the server when the page unloads.
</div>
</li>
<li class="method">
<div class="name">setPostVarName</div>
<div class="methodsignature"><code>void <strong>setPostVarName</strong>(String <em>postVarName</em>)</code></div>
<div class="summary">
<p>
[<em>not available after first message logged</em>]
</p>
<p>
Sets the post variable name whose value will the formatted log message(s) for
each request.
</p>
<p>
Default value is <code>data</code>.
</p>
<p><strong>Notes</strong></p>
<ul>
<li>
This has no effect if the current layout is an
<code><a href="#httppostdatalayout">HttpPostDataLayout</a></code>.
</li>
</ul>
</div>
</li>
<li class="method">
<div class="name">getPostVarName</div>
<div class="methodsignature"><code>String <strong>getPostVarName</strong>()</code></div>
<div class="summary">
Returns the post variable name whose value will the formatted log message(s) for
each request.
</div>
</li>
<li class="method">
<div class="name">setTimed</div>
<div class="methodsignature"><code>void <strong>setTimed</strong>(Boolean <em>timed</em>)</code></div>
<div class="summary">
<p>
[<em>not available after first message logged</em>]
</p>
<p>
Whether to send log messages to the server at regular, timed intervals.
</p>
<p>
Default value is <code>false</code>.
</p>
</div>
</li>
<li class="method">
<div class="name">isTimed</div>
<div class="methodsignature"><code>Boolean <strong>isTimed</strong>()</code></div>
<div class="summary">
Returns whether log messages are sent to the server at regular, timed intervals.
</div>
</li>
<li class="method">
<div class="name">setWaitForResponse</div>
<div class="methodsignature"><code>void <strong>setWaitForResponse</strong>(Boolean <em>waitForResponse</em>)</code></div>
<div class="summary">
<p>
[<em>not available after first message logged</em>]
</p>
<p>
Sets whether to wait for a response from a previous HTTP request from this
appender before sending the next log message / batch of messages.
</p>
<p>
Default value is <code>false</code>.
</p>
</div>
</li>
<li class="method">
<div class="name">isWaitForResponse</div>
<div class="methodsignature"><code>Boolean <strong>isWaitForResponse</strong>()</code></div>
<div class="summary">
Returns whether the appender waits for a response from a previous HTTP request from this
appender before sending the next log message / batch of messages.
</div>
</li>
<li class="method">
<div class="name">setBatchSize</div>
<div class="methodsignature"><code>void <strong>setBatchSize</strong>(Number <em>batchSize</em>)</code></div>
<div class="summary">
<p>
[<em>not available after first message logged</em>]
</p>
<p>
Sets the number of log messages to send in each request. If not specified,
defaults to <code>1</code>.
</p>
<p><strong>Notes</strong></p>
<ul>
<li>
Setting this to a number greater than 1 means that the appender will wait
until it has forwarded that many valid log messages before sending any more.
This also means that if the page unloads for any reason and <code>sendAllOnUnload</code>
is not set to <code>true</code>, any log messages waiting in the queue will not be sent.
</li>
<li>
If batching is used in conjunction with timed sending of log messages,
messages will still be sent in batches of size <code>batchSize</code>,
regardless of how many log messages are queued by the time the timed
sending is invoked. Incomplete batches will not be sent except when the
page unloads, if <code>sendAllOnUnload</code> is set to <code>true</code>.
</li>
</ul>
</div>
</li>
<li class="method">
<div class="name">getBatchSize</div>
<div class="methodsignature"><code>Number <strong>getBatchSize</strong>()</code></div>
<div class="summary">
Returns the number of log messages sent in each request. See above for more details.
</div>
</li>
<li class="method">
<div class="name">setTimerInterval</div>
<div class="methodsignature"><code>void <strong>setTimerInterval</strong>(Number <em>timerInterval</em>)</code></div>
<div class="summary">
<p>
[<em>not available after first message logged</em>]
</p>
<p>
Sets the length of time in milliseconds between each sending of queued log
messages.
</p>
<p><strong>Notes</strong></p>
<ul>
<li>
<code>timerInterval</code> only has an effect in conjunction with
<code>timed</code> (set by <code>setTimed()</code>. If <code>timed</code>
is set to false then <code>timerInterval</code> has no effect.
</li>
<li>
Each time the queue of log messages or batches of messages is cleared,
the countdown to the next sending only starts once the final request
has been sent (and, if <code>waitForResponse</code> is set to <code>true</code>,
the final response received). This means that the actual interval at
which the queue of messages is cleared cannot be fixed.
</li>
</ul>
</div>
</li>
<li class="method">
<div class="name">getTimerInterval</div>
<div class="methodsignature"><code>Number <strong>getTimerInterval</strong>()</code></div>
<div class="summary">
Returns the length of time in milliseconds between each sending of queued log
messages. See above for more details.
</div>
</li>
<li class="method">
<div class="name">setRequestSuccessCallback</div>
<div class="methodsignature"><code>void <strong>setRequestSuccessCallback</strong>(Function <em>requestSuccessCallback</em>)</code></div>
<div class="summary">
<p>
Sets the function that is called whenever a successful request is made, called at the
point at which the response is received. This feature can be used to confirm
whether a request has been successful and act accordingly.
</p>
<p>
A single parameter, <code>xmlHttp</code>, is passed to the callback function.
This is the XMLHttpRequest object that performed the request.
</p>
</div>
</li>
<li class="method">
<div class="name">setFailCallback</div>
<div class="methodsignature"><code>void <strong>setFailCallback</strong>(Function <em>failCallback</em>)</code></div>
<div class="summary">
<p>
Sets the function that is called whenever any kind of failure occurs in the appender,
including browser deficiencies or configuration errors (e.g. supplying a
non-existent URL to the appender). This feature can be used to handle
AjaxAppender-specific errors.
</p>
<p>
A single parameter, <code>message</code>, is passed to the callback function.
This is the error-specific message that caused the failure.
</p>
</div>
</li>
<li class="method">
<div class="name">setSessionId</div>
<div class="methodsignature"><code>void <strong>setSessionId</strong>(String <em>sessionId</em>)</code></div>
<div class="summary">
Sets the session id sent to the server each time a request is made.
</div>
</li>
<li class="method">
<div class="name">getSessionId</div>
<div class="methodsignature"><code>String <strong>getSessionId</strong>()</code></div>
<div class="summary">
Returns the session id sent to the server each time a request is made.
</div>
</li>
<li class="method">
<div class="name">addHeader</div>
<div class="methodsignature"><code>void <strong>addHeader</strong>(String <em>name</em>,
String <em>value</em>)</code></div>
<div class="summary">
<p>
Adds an HTTP header that is sent with each request.
</p>
<p>
<strong>Since: 1.4.3</strong>
</p>
</div>
</li>
<li class="method">
<div class="name">getHeaders</div>
<div class="methodsignature"><code>Array <strong>getHeaders</strong>()</code></div>
<div class="summary">
Returns an array of the additional headers that are sent with each HTTP request.
Each array item is an object with properties <code>name</code> and
<code>value</code>.
<p>
<strong>Since: 1.4.3</strong>
</p>
</div>
</li>
<li class="method">
<div class="name">sendAll</div>
<div class="methodsignature"><code>void <strong>sendAll</strong>()</code></div>
<div class="summary">
Sends all log messages in the queue. If log messages are batched then only completed
batches are sent.
</div>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="popupappender">
<h3>PopUpAppender</h3>
<p class="editions">Editions: <strong>Standard</strong></p>
<p>
Logs messages to a pop-up console window (note: you will need to disable pop-up
blockers to use it). The pop-up displays a list of all log messages, and has
the following features:
</p>
<ul>
<li>log messages are colour-coded by severity;</li>
<li>log messages are displayed in a monospace font to allow easy readability;</li>
<li>switchable wrap mode to allow wrapping of long lines</li>
<li>all whitespace in log messages is honoured (except in wrap mode);</li>
<li>filters to show and hide messages of a particular level;</li>
<li>
search facility that allows searching of log messages as you type, with the
following features:
<ul>
<li>supports regular expressions;</li>
<li>case sensitive or insensitive matching;</li>
<li>buttons to navigate through all the matches;</li>
<li>switch to highlight all matches;</li>
<li>switch to filter out all log messages that contain no matches;</li>
<li>switch to enable or disable the search;</li>
<li>search is dynamically applied to every log message as it is added to the console.</li>
</ul>
</li>
<li>switch to toggle between logging from the top down and from the bottom up;</li>
<li>switch to turn automatic scrolling when a new message is logged on and off;</li>
<li>switch to turn off all logging to the pop-up (useful if a timer is generating unwanted log messages);</li>
<li>optional configurable limit to the number of log message that are displayed. If
set and this limit is reached, each new log message will cause the oldest one to
be discarded;</li>
<li>grouped log messages. Groups may be nested and each has a button to show or hide the log messages in that group;</li>
<li>clear button to allow user to delete all current log messages.</li>
<li>
command prompt with up/down arrow history. Command line functions may be added
to the appender. Several command line functions are built in:
<ul class="propertieslist">
<li class="method">
<div class="methodsignature"><code><strong>$</strong>(String <em>id</em>)</code></div>
<div class="summary">
Prints a string representation of a single element with the id supplied.
</div>
</li>
<li class="method">
<div class="methodsignature"><code><strong>dir</strong>(Object <em>obj</em>)</code></div>
<div class="summary">
Prints a list of a properties of the object supplied.
</div>
</li>
<li class="method">
<div class="methodsignature"><code><strong>dirxml</strong>(HTMLElement <em>el</em>)</code></div>
<div class="summary">
Prints the XML source code of an HTML or XML element
</div>
</li>
<li class="method">
<div class="methodsignature"><code><strong>cd</strong>(Object <em>win</em>)</code></div>
<div class="summary">
Changes the scope of execution of commands to the named frame or window (either a
window/frame name or a reference to a window object may be supplied).
</div>
</li>
<li class="method">
<div class="methodsignature"><code><strong>clear</strong>()</code></div>
<div class="summary">
Clears the console.
</div>
</li>
<li class="method">
<div class="methodsignature"><code><strong>keys</strong>(Object <em>obj</em>)</code></div>
<div class="summary">
Prints a list of the names of all properties of the object supplied.
</div>
</li>
<li class="method">
<div class="methodsignature"><code><strong>values</strong>(Object <em>obj</em>)</code></div>
<div class="summary">
Prints a list of the values of all properties of the object supplied.
</div>
</li>
<li class="method">
<div class="methodsignature"><code><strong>expansionDepth</strong>(Number <em>depth</em>)</code></div>
<div class="summary">
Sets the number of levels of expansion of objects that are displayed by
the command line. The default value is 1.
</div>
</li>
</ul>
</li>
</ul>
<p><strong>Notes</strong></p>
<ul>
<li>
<p>
The default layout for this appender is <code><a href="#patternlayout">PatternLayout</a></code>
with pattern string
</p>
<p>
<code>%d{HH:mm:ss} %-5p - %m{1}%n</code>
</p>
</li>
</ul>
<h4>Constructor</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">PopUpAppender</div>
<div class="methodsignature">
<code><strong>PopUpAppender</strong>([Boolean <em>lazyInit</em>,
Boolean <em>initiallyMinimized</em>, Boolean <em>useDocumentWrite</em>,
Number <em>width</em>, Number <em>height</em>])</code>
</div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">lazyInit</code>
[<em>optional</em>]
<div>
Set this to <code>true</code> to open the pop-up only when the first log
message reaches the appender. Otherwise, the pop-up window opens as soon as the
appender is created. If not specified, defaults to <code>false</code>.
</div>
</li>
<li class="param">
<code class="paramname">initiallyMinimized</code>
[<em>optional</em>]
<div>
<p>
Whether the console window should start off hidden / minimized.
If not specified, defaults to <code>false</code>.
</p>
</div>
</li>
<li class="param">
<code class="paramname">useDocumentWrite</code>
[<em>optional</em>]
<div>
<p>
Specifies how the console window is created. By default, the console window is
created dynamically using <code>document</code>'s <code>write</code> method. This has the
advantage of keeping all the code in one single JavaScript file. However, if your
page sets <code>document.domain</code> then the browser prevents script access to
a window unless it too has the same value set for <code>document.domain</code>. To
get round this issue, you can set <code>useDocumentWrite</code> to <code>false</code>
and log4javascript will instead use the external HTML file <code>console.html</code>
(or <code>console_uncompressed.html</code> if you're using an uncompressed version of
log4javascript.js), which must be placed in the same directory as your log4javascript.js file.
</p>
<p>
Note that if <code>useDocumentWrite</code> is set to <code>true</code>, the old pop-up
window will always be closed and a new one created whenever the page is refreshed, even
if <code>setUseOldPopUp(true)</code> has been called.
</p>
<p>
In general it's simpler to use the <code>document.write</code> method, so unless your
page needs to set <code>document.domain</code>, <code>useDocumentWrite</code> should
be set to <code>true</code>.
</p>
<p>
If not specified, defaults to <code>true</code>.
</p>
</div>
</li>
<li class="param">
<code class="paramname">width</code>
[<em>optional</em>]
<div>
The outer width in pixels of the pop-up window. If not specified,
defaults to <code>600</code>.
</div>
</li>
<li class="param">
<code class="paramname">height</code>
[<em>optional</em>]
<div>
The outer height in pixels of the pop-up window. If not specified,
defaults to <code>400</code>.
</div>
</li>
</ul>
</li>
</ul>
<h4>Methods</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">isInitiallyMinimized</div>
<div class="methodsignature"><code>Boolean <strong>isInitiallyMinimized</strong>()</code></div>
<div class="summary">
Returns whether the console window starts off hidden / minimized.
</div>
</li>
<li class="method">
<div class="name">setInitiallyMinimized</div>
<div class="methodsignature"><code>void <strong>setInitiallyMinimized</strong>(Boolean <em>initiallyMinimized</em>)</code></div>
<div class="summary">
[<em>not available after initialization</em>]
<br />
Sets whether the console window should start off hidden / minimized.
</div>
</li>
<li class="method">
<div class="name">isFocusPopUp</div>
<div class="methodsignature"><code>Boolean <strong>isFocusPopUp</strong>()</code></div>
<div class="summary">
Returns whether the pop-up window is focussed (i.e. brought it to the front)
when a new log message is added. Default value is <code>false</code>.
</div>
</li>
<li class="method">
<div class="name">setFocusPopUp</div>
<div class="methodsignature"><code>void <strong>setFocusPopUp</strong>(Boolean <em>focusPopUp</em>)</code></div>
<div class="summary">
Sets whether to focus the pop-up window (i.e. bring it to the front)
when a new log message is added.
</div>
</li>
<li class="method">
<div class="name">isUseOldPopUp</div>
<div class="methodsignature"><code>Boolean <strong>isUseOldPopUp</strong>()</code></div>
<div class="summary">
<p>
Returns whether the same pop-up window is used if the main page is
reloaded. If set to <code>true</code>, when the page is reloaded
a line is drawn in the pop-up and subsequent log messages are added
to the same pop-up. Otherwise, a new pop-up window is created that
replaces the original pop-up. If not specified, defaults to
<code>true</code>.
</p>
<p><strong>Notes</strong></p>
<ul>
<li>
In Internet Explorer 5, the browser prevents this from working
properly, so a new pop-up window is always created when the main
page reloads. Also, the original pop-up does not get closed.
</li>
</ul>
</div>
</li>
<li class="method">
<div class="name">setUseOldPopUp</div>
<div class="methodsignature"><code>void <strong>setUseOldPopUp</strong>(Boolean <em>useOldPopUp</em>)</code></div>
<div class="summary">
[<em>not available after initialization</em>]
<br />
Sets whether to use the same pop-up window if the main page is reloaded.
See <code>isUseOldPopUp</code> above for details.
</div>
</li>
<li class="method">
<div class="name">isComplainAboutPopUpBlocking</div>
<div class="methodsignature"><code>Boolean <strong>isComplainAboutPopUpBlocking</strong>()</code></div>
<div class="summary">
Returns whether an alert is shown to the user when the pop-up window
cannot be created as a result of a pop-up blocker. Default value is <code>true</code>.
</div>
</li>
<li class="method">
<div class="name">setComplainAboutPopUpBlocking</div>
<div class="methodsignature"><code>void <strong>setComplainAboutPopUpBlocking</strong>(Boolean <em>complainAboutPopUpBlocking</em>)</code></div>
<div class="summary">
[<em>not available after initialization</em>]
<br />
Sets whether to announce to show an alert to the user when the pop-up window
cannot be created as a result of a pop-up blocker.
</div>
</li>
<li class="method">
<div class="name">isNewestMessageAtTop</div>
<div class="methodsignature"><code>Boolean <strong>isNewestMessageAtTop</strong>()</code></div>
<div class="summary">
Returns whether new log messages are displayed at the top of the pop-up window.
Default value is <code>false</code> (i.e. log messages are appended to the bottom of the window).
</div>
</li>
<li class="method">
<div class="name">setNewestMessageAtTop</div>
<div class="methodsignature"><code>void <strong>setNewestMessageAtTop</strong>(Boolean <em>newestMessageAtTop</em>)</code></div>
<div class="summary">
Sets whether to display new log messages at the top inside the pop-up window.
</div>
</li>
<li class="method">
<div class="name">isScrollToLatestMessage</div>
<div class="methodsignature"><code>Boolean <strong>isScrollToLatestMessage</strong>()</code></div>
<div class="summary">
Returns whether the pop-up window scrolls to display the latest log message when a new message
is logged. Default value is <code>true</code>.
</div>
</li>
<li class="method">
<div class="name">setScrollToLatestMessage</div>
<div class="methodsignature"><code>void <strong>setScrollToLatestMessage</strong>(Boolean <em>scrollToLatestMessage</em>)</code></div>
<div class="summary">
Sets whether to scroll the pop-up window to display the latest log message when a new message
is logged.
</div>
</li>
<li class="method">
<div class="name">isReopenWhenClosed</div>
<div class="methodsignature"><code>Boolean <strong>isReopenWhenClosed</strong>()</code></div>
<div class="summary">
Returns whether the pop-up window reopens automatically after being closed when a new log message is logged.
Default value is <code>false</code>.
</div>
</li>
<li class="method">
<div class="name">setReopenWhenClosed</div>
<div class="methodsignature"><code>void <strong>setReopenWhenClosed</strong>(Boolean <em>reopenWhenClosed</em>)</code></div>
<div class="summary">
Sets whether to reopen the pop-up window automatically after being closed when a new log message is logged.
</div>
</li>
<li class="method">
<div class="name">getWidth</div>
<div class="methodsignature"><code>Number <strong>getWidth</strong>()</code></div>
<div class="summary">
Returns the outer width in pixels of the pop-up window.
</div>
</li>
<li class="method">
<div class="name">setWidth</div>
<div class="methodsignature"><code>void <strong>setWidth</strong>(Number <em>width</em>)</code></div>
<div class="summary">
[<em>not available after initialization</em>]
<br />
Sets the outer width in pixels of the pop-up window.
</div>
</li>
<li class="method">
<div class="name">getHeight</div>
<div class="methodsignature"><code>Number <strong>getHeight</strong>()</code></div>
<div class="summary">
[<em>not available after initialization</em>]
<br />
Returns the outer height in pixels of the pop-up window.
</div>
</li>
<li class="method">
<div class="name">setHeight</div>
<div class="methodsignature"><code>void <strong>setHeight</strong>(Number <em>height</em>)</code></div>
<div class="summary">
Sets the outer height in pixels of the pop-up window.
</div>
</li>
<li class="method">
<div class="name">getMaxMessages</div>
<div class="methodsignature"><code>Number <strong>getMaxMessages</strong>()</code></div>
<div class="summary">
Returns the largest number of log messages that are displayed and stored
by the the console. Once reached, a new log message wil cause the
oldest message to be discarded. Default value is <code>null</code>, which means no
limit is applied.
</div>
</li>
<li class="method">
<div class="name">setMaxMessages</div>
<div class="methodsignature"><code>void <strong>setMaxMessages</strong>(Number <em>maxMessages</em>)</code></div>
<div class="summary">
[<em>not available after initialization</em>]
<br />
Sets the largest number of messages displayed and stored by the console window. Set
this to <code>null</code> to make this number unlimited.
</div>
</li>
<li class="method">
<div class="name">isShowCommandLine</div>
<div class="methodsignature"><code>Boolean <strong>isShowCommandLine</strong>()</code></div>
<div class="summary">
Returns whether the console includes a command line.
Default value is <code>true</code>.
</div>
</li>
<li class="method">
<div class="name">setShowCommandLine</div>
<div class="methodsignature"><code>void <strong>setShowCommandLine</strong>(Boolean <em>showCommandLine</em>)</code></div>
<div class="summary">
Sets whether the console includes a command line.
</div>
</li>
<li class="method">
<div class="name">getCommandLineObjectExpansionDepth</div>
<div class="methodsignature"><code>Number <strong>getCommandLineObjectExpansionDepth</strong>()</code></div>
<div class="summary">
Returns the number of levels to expand when an object value is logged to the console.
Each property of an object above this threshold will be expanded if it is itself an object
or array, otherwise its string representation will be displayed. Default value is 1 (i.e.
the properties of the object logged will be displayed in their string representation but
not expanded).
</div>
</li>
<li class="method">
<div class="name">setCommandLineObjectExpansionDepth:</div>
<div class="methodsignature"><code>void <strong>setCommandLineObjectExpansionDepth</strong>(Number <em>expansionDepth</em>)</code></div>
<div class="summary">
Sets the number of levels to expand when an object value is logged to the console.
</div>
</li>
<li class="method">
<div class="name">getCommandWindow</div>
<div class="methodsignature"><code>Window <strong>getCommandWindow</strong>()</code></div>
<div class="summary">
Returns a reference to the window in which commands typed into the command line
are currently being executed.
</div>
</li>
<li class="method">
<div class="name">setCommandWindow</div>
<div class="methodsignature"><code>void <strong>setCommandWindow</strong>(Window <em>commandWindow</em>)</code></div>
<div class="summary">
Sets the window in which commands typed into the command line are executed.
</div>
</li>
<li class="method">
<div class="name">getCommandLayout</div>
<div class="methodsignature"><code>Number <strong>getCommandLayout</strong>()</code></div>
<div class="summary">
Returns the layout used to format the output for commands typed into the command line.
The default value is a <code><a href="#patternlayout">PatternLayout</a></code> with
pattern string <code>%m</code>
</div>
</li>
<li class="method">
<div class="name">setCommandLayout</div>
<div class="methodsignature"><code>void <strong>setCommandLayout</strong>(Layout <em>commandLayout</em>)</code></div>
<div class="summary">
Sets the layout used to format the output for commands typed into the command line.
</div>
</li>
<li class="method">
<div class="name">clear</div>
<div class="methodsignature"><code>void <strong>clear</strong>()</code></div>
<div class="summary">
Clears all messages from the console window.
</div>
</li>
<li class="method">
<div class="name">close</div>
<div class="methodsignature"><code>void <strong>close</strong>()</code></div>
<div class="summary">
Closes the pop-up window.
</div>
</li>
<li class="method">
<div class="name">show</div>
<div class="methodsignature"><code>void <strong>show</strong>()</code></div>
<div class="summary">
Opens the pop-up window, if not already open.
</div>
</li>
<li class="method">
<div class="name">hide</div>
<div class="methodsignature"><code>void <strong>hide</strong>()</code></div>
<div class="summary">
Closes the pop-up window.
</div>
</li>
<li class="method">
<div class="name">focus</div>
<div class="methodsignature"><code>void <strong>focus</strong>()</code></div>
<div class="summary">
Brings the console window to the top and gives it the focus.
</div>
</li>
<li class="method">
<div class="name">focusCommandLine</div>
<div class="methodsignature"><code>void <strong>focusCommandLine</strong>()</code></div>
<div class="summary">
Brings the console window to the top and gives the focus to the command line.
</div>
</li>
<li class="method">
<div class="name">focusSearch</div>
<div class="methodsignature"><code>void <strong>focusSearch</strong>()</code></div>
<div class="summary">
Brings the console window to the top and gives the focus to the search box.
</div>
</li>
<li class="method">
<div class="name">evalCommandAndAppend</div>
<div class="methodsignature"><code>void <strong>evalCommandAndAppend</strong>(String <em>expr</em>)</code></div>
<div class="summary">
Evaluates the expression and appends the result to the console.
</div>
</li>
<li class="method">
<div class="name">addCommandLineFunction</div>
<div class="methodsignature"><code>void <strong>addCommandLineFunction</strong>(String <em>functionName</em>, Function <em>commandLineFunction</em>)</code></div>
<div class="summary">
<p>
Adds a function with the name specified to the list of functions available on the command line.
This feature may be used to add custom functions to the command line.
</p>
<p>
When you call the function on the command line, <code>commandLineFunction</code> is executed with the
following three parameters:
</p>
<ul>
<li><em>appender</em>. A reference to the appender in which the command was executed;</li>
<li><em>args</em>.
An array-like list of parameters passed into the function on the command line
(actually a reference to the <code>arguments</code> object representing the parameters passed
into the function by the user);</li>
<li><em>returnValue</em>. This is an object with two properties that allow the function to control
how the result is displayed:
<ul>
<li><em>appendResult</em>. A boolean value that determines whether the returned value from this
function is appended to the console. The default value is <code>true</code>;</li>
<li><em>isError</em>. A boolean value that specifies whether the output of this function
should be displayed as an error. The default value is <code>false</code>.</li>
</ul>
</li>
</ul>
<p>
The value returned by the function is formatted by the command layout and appended to the console.
</p>
</div>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="inpageappender">
<h3>InPageAppender</h3>
<p class="editions">Editions: <strong>Standard</strong></p>
<p>
Logs messages to a console window in the page. The console is identical
to that used by the <code><a href="#popupappender">PopUpAppender</a></code>, except
for the absence of a 'Close' button.
</p>
<p><strong>Notes</strong></p>
<ul>
<li>
Prior to log4javascript 1.3, InPageAppender was known as InlineAppender.
For the sake of backwards compatibility, InlineAppender is still included in
1.3 and later as an alias for InPageAppender.
</li>
<li>
<p>
The default layout for this appender is <code><a href="#patternlayout">PatternLayout</a></code>
with pattern string
</p>
<p>
<code>%d{HH:mm:ss} %-5p - %m{1}%n</code>
</p>
</li>
</ul>
<h4>Constructor</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">InPageAppender</div>
<div class="methodsignature">
<code><strong>InPageAppender</strong>(HTMLElement <em>container</em>[,
Boolean <em>lazyInit</em>, Boolean <em>initiallyMinimized</em>,
Boolean <em>useDocumentWrite</em>, String <em>width</em>, String <em>height</em>])</code>
</div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">container</code>
<div>
The container element for the console window. This should be an HTML element.
</div>
</li>
<li class="param">
<code class="paramname">lazyInit</code>
[<em>optional</em>]
<div>
Set this to <code>true</code> to create the console only when the first log
message reaches the appender. Otherwise, the console is initialized as soon as the
appender is created. If not specified, defaults to <code>true</code>.
</div>
</li>
<li class="param">
<code class="paramname">initiallyMinimized</code>
[<em>optional</em>]
<div>
<p>
Whether the console window should start off hidden / minimized.
If not specified, defaults to <code>false</code>.
</p>
<p><strong>Notes</strong></p>
<ul>
<li>
In Safari (and possibly other browsers) hiding an <code>iframe</code>
resets its document, thus destroying the console window.
</li>
</ul>
</div>
</li>
<li class="param">
<code class="paramname">useDocumentWrite</code>
[<em>optional</em>]
<div>
<p>
Specifies how the console window is created. By default, the console window is
created dynamically using <code>document</code>'s <code>write</code> method. This has the
advantage of keeping all the code in one single JavaScript file. However, if your
page sets <code>document.domain</code> then the browser prevents script access to
a window unless it too has the same value set for <code>document.domain</code>. To
get round this issue, you can set <code>useDocumentWrite</code> to <code>false</code>
and log4javascript will instead use the external HTML file <code>console.html</code>
(or <code>console_uncompressed.html</code> if you're using an uncompressed version of
log4javascript.js), which must be placed in the same directory as your log4javascript.js file.
</p>
<p>
In general it's simpler to use the <code>document.write</code> method, so unless your
page needs to set <code>document.domain</code>, <code>useDocumentWrite</code> should
be set to <code>true</code>.
</p>
<p>
If not specified, defaults to <code>true</code>.
</p>
</div>
</li>
<li class="param">
<code class="paramname">width</code>
[<em>optional</em>]
<div>
The width of the console window. Any valid CSS length may be used. If not
specified, defaults to <code>100%</code>.
</div>
</li>
<li class="param">
<code class="paramname">height</code>
[<em>optional</em>]
<div>
The height of the console window. Any valid CSS length may be used. If not
specified, defaults to <code>250px</code>.
</div>
</li>
</ul>
</li>
</ul>
<h4>Methods</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">addCssProperty</div>
<div class="methodsignature"><code>void <strong>addCssProperty</strong>(String <em>name</em>, String <em>value</em>)</code></div>
<div class="summary">
Sets a CSS style property on the HTML element containing the console iframe.
</div>
</li>
<li class="method">
<div class="name">isVisible</div>
<div class="methodsignature"><code>Boolean <strong>isVisible</strong>()</code></div>
<div class="summary">
Returns whether the console window is currently visible.
</div>
</li>
<li class="method">
<div class="name">isInitiallyMinimized</div>
<div class="methodsignature"><code>Boolean <strong>isInitiallyMinimized</strong>()</code></div>
<div class="summary">
Returns whether the console window starts off hidden / minimized.
</div>
</li>
<li class="method">
<div class="name">setInitiallyMinimized</div>
<div class="methodsignature"><code>void <strong>setInitiallyMinimized</strong>(Boolean <em>initiallyMinimized</em>)</code></div>
<div class="summary">
[<em>not available after initialization</em>]
<br />
Sets whether the console window should start off hidden / minimized.
</div>
</li>
<li class="method">
<div class="name">isNewestMessageAtTop</div>
<div class="methodsignature"><code>Boolean <strong>isNewestMessageAtTop</strong>()</code></div>
<div class="summary">
Returns whether new log messages are displayed at the top of the console window.
</div>
</li>
<li class="method">
<div class="name">setNewestMessageAtTop</div>
<div class="methodsignature"><code>void <strong>setNewestMessageAtTop</strong>(Boolean <em>newestMessageAtTop</em>)</code></div>
<div class="summary">
Sets whether to display new log messages at the top inside the console window.
</div>
</li>
<li class="method">
<div class="name">isScrollToLatestMessage</div>
<div class="methodsignature"><code>Boolean <strong>isScrollToLatestMessage</strong>()</code></div>
<div class="summary">
Returns whether the pop-up window scrolls to display the latest log message when a new message
is logged.
</div>
</li>
<li class="method">
<div class="name">setScrollToLatestMessage</div>
<div class="methodsignature"><code>void <strong>setScrollToLatestMessage</strong>(Boolean <em>scrollToLatestMessage</em>)</code></div>
<div class="summary">
Sets whether to scroll the console window to display the latest log message when a new message
is logged.
</div>
</li>
<li class="method">
<div class="name">getWidth</div>
<div class="methodsignature"><code>String <strong>getWidth</strong>()</code></div>
<div class="summary">
Returns the outer width of the console window.
</div>
</li>
<li class="method">
<div class="name">setWidth</div>
<div class="methodsignature"><code>void <strong>setWidth</strong>(String <em>width</em>)</code></div>
<div class="summary">
[<em>not available after initialization</em>]
<br />
Sets the outer width of the console window. Any valid CSS length may be used.
</div>
</li>
<li class="method">
<div class="name">getHeight</div>
<div class="methodsignature"><code>String <strong>getHeight</strong>()</code></div>
<div class="summary">
Returns the outer height of the console window.
</div>
</li>
<li class="method">
<div class="name">setHeight</div>
<div class="methodsignature"><code>void <strong>setHeight</strong>(String <em>height</em>)</code></div>
<div class="summary">
[<em>not available after initialization</em>]
<br />
Sets the outer height of the console window. Any valid CSS length may be used.
</div>
</li>
<li class="method">
<div class="name">getMaxMessages</div>
<div class="methodsignature"><code>Number <strong>getMaxMessages</strong>()</code></div>
<div class="summary">
Returns the largest number of messages displayed and stored by the console window.
</div>
</li>
<li class="method">
<div class="name">setMaxMessages</div>
<div class="methodsignature"><code>void <strong>setMaxMessages</strong>(Number <em>maxMessages</em>)</code></div>
<div class="summary">
[<em>not available after initialization</em>]
<br />
Sets the largest number of messages displayed and stored by the console window. Set
this to <code>null</code> to make this number unlimited.
</div>
</li>
<li class="method">
<div class="name">isShowCommandLine</div>
<div class="methodsignature"><code>Boolean <strong>isShowCommandLine</strong>()</code></div>
<div class="summary">
Returns whether the console includes a command line.
Default value is <code>true</code>.
</div>
</li>
<li class="method">
<div class="name">setShowCommandLine</div>
<div class="methodsignature"><code>void <strong>setShowCommandLine</strong>(Boolean <em>showCommandLine</em>)</code></div>
<div class="summary">
Sets whether the console includes a command line.
</div>
</li>
<li class="method">
<div class="name">getCommandLineObjectExpansionDepth</div>
<div class="methodsignature"><code>Number <strong>getCommandLineObjectExpansionDepth</strong>()</code></div>
<div class="summary">
Returns the number of levels to expand when an object value is logged to the console.
Each property of an object above this threshold will be expanded if it is itself an object
or array, otherwise its string representation will be displayed. Default value is 1 (i.e.
the properties of the object logged will be displayed in their string representation but
not expanded).
</div>
</li>
<li class="method">
<div class="name">setCommandLineObjectExpansionDepth:</div>
<div class="methodsignature"><code>void <strong>setCommandLineObjectExpansionDepth</strong>(Number <em>expansionDepth</em>)</code></div>
<div class="summary">
Sets the number of levels to expand when an object value is logged to the console.
</div>
</li>
<li class="method">
<div class="name">getCommandWindow</div>
<div class="methodsignature"><code>Window <strong>getCommandWindow</strong>()</code></div>
<div class="summary">
Returns a reference to the window in which commands typed into the command line
are currently being executed.
</div>
</li>
<li class="method">
<div class="name">setCommandWindow</div>
<div class="methodsignature"><code>void <strong>setCommandWindow</strong>(Window <em>commandWindow</em>)</code></div>
<div class="summary">
Sets the window in which commands typed into the command line are executed.
</div>
</li>
<li class="method">
<div class="name">getCommandLayout</div>
<div class="methodsignature"><code>Number <strong>getCommandLayout</strong>()</code></div>
<div class="summary">
Returns the layout used to format the output for commands typed into the command line.
The default value is a <code><a href="#patternlayout">PatternLayout</a></code> with
pattern string <code>%m</code>
</div>
</li>
<li class="method">
<div class="name">setCommandLayout</div>
<div class="methodsignature"><code>void <strong>setCommandLayout</strong>(Layout <em>commandLayout</em>)</code></div>
<div class="summary">
Sets the layout used to format the output for commands typed into the command line.
</div>
</li>
<li class="method">
<div class="name">clear</div>
<div class="methodsignature"><code>void <strong>clear</strong>()</code></div>
<div class="summary">
Clears all messages from the console window.
</div>
</li>
<li class="method">
<div class="name">show</div>
<div class="methodsignature"><code>void <strong>show</strong>()</code></div>
<div class="summary">
<p>
Shows / unhides the console window.
</p>
<p><strong>Notes</strong></p>
<ul>
<li>
In Safari (and possibly other browsers), hiding an <code>iframe</code>
resets its document, thus destroying the console window.
</li>
</ul>
</div>
</li>
<li class="method">
<div class="name">hide</div>
<div class="methodsignature"><code>void <strong>hide</strong>()</code></div>
<div class="summary">
<p>
Hides / minimizes the console window.
</p>
<p><strong>Notes</strong></p>
<ul>
<li>
In Safari (and possibly other browsers), hiding an <code>iframe</code>
resets its document, thus destroying the console window.
</li>
</ul>
</div>
</li>
<li class="method">
<div class="name">close</div>
<div class="methodsignature"><code>void <strong>close</strong>()</code></div>
<div class="summary">
Removes the console window iframe from the main document.
</div>
</li>
<li class="method">
<div class="name">focus</div>
<div class="methodsignature"><code>void <strong>focus</strong>()</code></div>
<div class="summary">
Brings the console window to the top and gives it the focus.
</div>
</li>
<li class="method">
<div class="name">focusCommandLine</div>
<div class="methodsignature"><code>void <strong>focusCommandLine</strong>()</code></div>
<div class="summary">
Brings the console window to the top and gives the focus to the command line.
</div>
</li>
<li class="method">
<div class="name">focusSearch</div>
<div class="methodsignature"><code>void <strong>focusSearch</strong>()</code></div>
<div class="summary">
Brings the console window to the top and gives the focus to the search box.
</div>
</li>
<li class="method">
<div class="name">evalCommandAndAppend</div>
<div class="methodsignature"><code>void <strong>evalCommandAndAppend</strong>(String <em>expr</em>)</code></div>
<div class="summary">
Evaluates the expression and appends the result to the console.
</div>
</li>
<li class="method">
<div class="name">addCommandLineFunction</div>
<div class="methodsignature"><code>void <strong>addCommandLineFunction</strong>(String <em>functionName</em>, Function <em>commandLineFunction</em>)</code></div>
<div class="summary">
<p>
Adds a function with the name specified to the list of functions available on the command line.
This feature may be used to add custom functions to the command line.
</p>
<p>
When you call the function on the command line, <code>commandLineFunction</code> is executed with the
following three parameters:
</p>
<ul>
<li><em>appender</em>. A reference to the appender in which the command was executed;</li>
<li><em>args</em>.
An array-like list of parameters passed into the function on the command line
(actually a reference to an <code>arguments</code> object);</li>
<li><em>returnValue</em>. This is an object with two properties that allow the function to control
how the result is displayed:
<ul>
<li><em>appendResult</em>. A boolean value that determines whether the returned value from this
function is appended to the console. The default value is <code>true</code>;</li>
<li><em>isError</em>. A boolean value that specifies whether the output of this function
should be displayed as an error. The default value is <code>false</code>.</li>
</ul>
</li>
</ul>
<p>
The value returned by the function is formatted by the command layout and appended to the console.
</p>
</div>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="browserconsoleappender">
<h3>BrowserConsoleAppender</h3>
<p class="editions">Editions: <strong>Standardl</strong></p>
<p>
Writes log messages to the browser's built-in console, if present. This only works
currently in Safari, Opera and Firefox with the excellent
<a href="http://www.getfirebug.com" title="Firebug home page (opens in new window)"
target="_blank">Firebug</a> extension installed.
</p>
<p><strong>Notes</strong></p>
<ul>
<li>
As of log4javascript 1.3, the default threshold for this appender is <code>DEBUG</code>
as opposed to <code>WARN</code> as it was previously;
</li>
<li>
<p>
As of version 1.3, log4javascript has explicit support for Firebug's logging. This includes
the following mapping of log4javascript's log levels onto Firebug's:
</p>
<ul>
<li>log4javascript <code>TRACE</code>, <code>DEBUG</code> -&gt; Firebug <code>debug</code></li>
<li>log4javascript <code>INFO</code> -&gt; Firebug <code>info</code></li>
<li>log4javascript <code>WARN</code> -&gt; Firebug <code>warn</code></li>
<li>log4javascript <code>ERROR</code>, <code>FATAL</code> -&gt; Firebug <code>error</code></li>
</ul>
<p>
... and the ability to pass objects into Firebug and take advantage of its object inspection.
This is because the default layout is now <code><a href="#nulllayout">NullLayout</a></code>,
which performs no formatting on an object.
</p>
</li>
</ul>
<h4>Constructor</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">BrowserConsoleAppender</div>
<div class="methodsignature"><code><strong>BrowserConsoleAppender</strong>()</code></div>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
</div>
<div id="layouts">
<h2>Layouts</h2>
<div id="layout">
<h3>Layout</h3>
<p>
There are a few methods common to all layouts:
</p>
<h4>Methods</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">format</div>
<div class="methodsignature"><code>String <strong>format</strong>(LoggingEvent <em>loggingEvent</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">loggingEvent</code>
</li>
</ul>
<div class="summary">
Formats the log message. You should override this method in your own layouts.
</div>
</li>
<li class="method">
<div class="name">ignoresThrowable</div>
<div class="methodsignature"><code>Boolean <strong>ignoresThrowable</strong>()</code></div>
<div class="summary">
Returns whether the layout ignores an error object in a logging event passed
to its <code>format</code> method.
</div>
</li>
<li class="method">
<div class="name">getContentType</div>
<div class="methodsignature"><code>String <strong>getContentType</strong>()</code></div>
<div class="summary">
Returns the content type of the output of the layout.
</div>
</li>
<li class="method">
<div class="name">allowBatching</div>
<div class="methodsignature"><code>Boolean <strong>allowBatching</strong>()</code></div>
<div class="summary">
Returns whether the layout's output is suitable for batching.
<code><a href="#jsonlayout">JsonLayout</a></code> and <code><a href="#xmllayout">XmlLayout</a></code>
are the only built-in layouts that return true for this method.
</div>
</li>
<li class="method">
<div class="name">getDataValues</div>
<div class="methodsignature"><code>Array <strong>getDataValues</strong>(LoggingEvent <em>loggingEvent</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">loggingEvent</code>
</li>
</ul>
<div class="summary">
Used internally by log4javascript in constructing formatted output for some layouts.
</div>
</li>
<li class="method">
<div class="name">setKeys</div>
<div class="methodsignature"><code>void <strong>setKeys</strong>(String <em>loggerKey</em>,
String <em>timeStampKey</em>, String <em>levelKey</em>, String <em>messageKey</em>,
String <em>exceptionKey</em>, String <em>urlKey</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">loggerKey</code>
<div>
Parameter to use for the log message's logger name. Default is <code>logger</code>.
</div>
</li>
<li class="param">
<code class="paramname">timeStampKey</code>
<div>
Parameter to use for the log message's timestamp. Default is <code>timestamp</code>.
</div>
</li>
<li class="param">
<code class="paramname">levelKey</code>
<div>
Parameter to use for the log message's level. Default is <code>level</code>.
</div>
</li>
<li class="param">
<code class="paramname">messageKey</code>
<div>
Parameter to use for the message itself. Default is <code>message</code>.
</div>
</li>
<li class="param">
<code class="paramname">exceptionKey</code>
<div>
Parameter to use for the log message's error (exception). Default is <code>exception</code>.
</div>
</li>
<li class="param">
<code class="paramname">urlKey</code>
<div>
Parameter to use for the current page URL. Default is <code>url</code>.
</div>
</li>
</ul>
<div class="summary">
This method is used to change the default keys used to create formatted name-value pairs
for the properties of a log message, for layouts that do this. These layouts are
<code><a href="#jsonlayout">JsonLayout</a></code> and
<code><a href="#httppostdatalayout">HttpPostDataLayout</a></code>.
</div>
</li>
<li class="method">
<div class="name">setCustomField</div>
<div class="methodsignature"><code>void <strong>setCustomField</strong>(String <em>name</em>,
String <em>value</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">name</code>
<div>
Name of the custom property you wish to be included in the formmtted output.
</div>
</li>
<li class="param">
<code class="paramname">value</code>
<div>
Value of the custom property you wish to be included in the formatted output.
</div>
</li>
</ul>
<div class="summary">
Some layouts (<code><a href="#jsonlayout">JsonLayout</a></code>,
<code><a href="#httppostdatalayout">HttpPostDataLayout</a></code>,
<code><a href="#patternlayout">PatternLayout</a></code> and
<code><a href="#xmllayout">XmlLayout</a></code>) allow you to set
custom fields (e.g. a session id to send to the server) to the
formatted output. Use this method to set a custom field. If there
is already a custom field with the specified name, its value will
be updated with <code>value</code>.
</div>
<p><strong>Notes</strong></p>
<ul>
<li>
<p>
From version 1.4, the custom field value may be a function. In this
case, the function is run at the time the layout's format method is called,
with the following two parameters:
</p>
<ul>
<li><em>layout</em>. A reference to the layout being used;</li>
<li><em>loggingEvent</em>. A reference to the logging event being formatted.</li>
</ul>
</li>
</ul>
</li>
<li class="method">
<div class="name">hasCustomFields</div>
<div class="methodsignature"><code>Boolean <strong>hasCustomFields</strong>()</code></div>
<div class="summary">
Returns whether the layout has any custom fields.
</div>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="nulllayout">
<h3>NullLayout</h3>
<p class="editions">Editions: <strong>All</strong></p>
<p>
The most basic layout. NullLayout's <code>format()</code> methods performs no
formatting at all and simply returns the message logged.
</p>
<h4>Constructor</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">NullLayout</div>
<div class="methodsignature"><code><strong>NullLayout</strong>()</code></div>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="simplelayout">
<h3>SimpleLayout</h3>
<p class="editions">Editions: <strong>Standard, Production</strong></p>
<p>
Provides basic formatting. SimpleLayout consists of the level of the log statement,
followed by " - " and then the log message itself. For example,
</p>
<p><code>DEBUG - Hello world</code></p>
<h4>Constructor</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">SimpleLayout</div>
<div class="methodsignature"><code><strong>SimpleLayout</strong>()</code></div>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="patternlayout">
<h3>PatternLayout</h3>
<p class="editions">Editions: <strong>All</strong></p>
<p>
Provides a flexible way of formatting a log message by means of a conversion pattern
string. The behaviour of this layout is a full implementation of <code>PatternLayout</code>
in log4j, with the exception of the set of conversion characters - log4javascript's is
necessarily a subset of that of log4j with a few additions of its own, since many of
the conversion characters in log4j only make sense in the context of Java.
</p>
<p>
The conversion pattern consists of literal text interspersed with special strings starting with
a % symbol called <em>conversion specifiers</em>. A conversion specifier consists of the
% symbol, a conversion character (possible characters are listed below) and
<em>format modifiers</em>. For full documentation of the conversion pattern, see
<a href="http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html" target="_blank">log4j's
documentation</a>. Below is a list of all conversion characters available in log4javascript.
</p>
<h4>Conversion characters</h4>
<table border="1" cellspacing="0">
<thead>
<tr>
<th>Conversion Character</th>
<th>Effect</th>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
<td>
<p>
Outputs log messages specified as an array.
</p>
<p>
Behaves exactly like <code>%m</code>, except that multiple log messages are
assumed to have been specified in the logging call as an array rather than
as multiple parameters.
</p>
<p>
<strong>Since: 1.4</strong>
</p>
</td>
</tr>
<tr>
<td>c</td>
<td>
<p>
Outputs the logger name.
</p>
</td>
</tr>
<tr>
<td>d</td>
<td>
<p>
Outputs the date of the logging event. The date conversion specifier
may be followed by a date format specifier enclosed between braces. For
example, <code>%d{HH:mm:ss,SSS}</code> or
<code>%d{dd MMM yyyy HH:mm:ss,SSS}</code>. If no date
format specifier is given then ISO8601 format is assumed.
</p>
<p>
The date format specifier is the same as that used by Java's
<code><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html"
target="_blank">SimpleDateFormat</a></code>. log4javascript
includes a full implementation of SimpleDateFormat's
<code>format</code> method, with the exception of the pattern letter
'z', (string representation of the timezone) for which the information
is not available in JavaScript.
</p>
</td>
</tr>
<tr>
<td>f</td>
<td>
<p>
Outputs the value of a custom field set on the layout. If present, the specifier gives
the index in the array of custom fields to use; otherwise, the first custom field in the
array is used.
</p>
<p>
<strong>Since: 1.3</strong>
</p>
</td>
</tr>
<tr>
<td>m</td>
<td>
<p>
Outputs the log messages of the logging event (i.e. the log
messages supplied by the client code).
</p>
<p>
As of version 1.4, multiple log messages may be supplied to logging calls.
<code>%m</code> displays each log message (using the rules below) one after
another, separated by spaces.
</p>
<p>
As of version 1.3, an object may be specified as the log message and will
be expanded to show its properties in the output, provided that a specifier
containing the number of levels to expand is provided. If no specifier is
provided then the message will be treated as a string regardless of its type.
For example, <code>%m{1}</code> will display an expansion of the object one
level deep, i.e. each property of the object will be displayed but if the
property value is itself an object it will not be expanded and will appear
as <code>[object Object]</code>.
</p>
</td>
</tr>
<tr>
<td>n</td>
<td>
<p>
Outputs a line separator.
</p>
</td>
</tr>
<tr>
<td>p</td>
<td>
<p>
Outputs the level of the logging event.
</p>
</td>
</tr>
<tr>
<td>r</td>
<td>
<p>
Outputs the number of milliseconds since log4javascript was initialized.
</p>
</td>
</tr>
<tr>
<td>%</td>
<td>
<p>
The sequence %% outputs a single percent sign.
</p>
</td>
</tr>
</tbody>
</table>
<h4>Static properties</h4>
<ul class="propertieslist">
<li class="property">
<div class="name">TTCC_CONVERSION_PATTERN</div>
<div class="summary">
Built-in conversion pattern, equivalent to <code>%r %p %c - %m%n</code>.
</div>
</li>
<li class="property">
<div class="name">DEFAULT_CONVERSION_PATTERN</div>
<div class="summary">
Built-in conversion pattern, equivalent to <code>%m%n</code>.
</div>
</li>
<li class="property">
<div class="name">ISO8601_DATEFORMAT</div>
<div class="summary">
Built-in date format (and also the default), equivalent to
<code>yyyy-MM-dd HH:mm:ss,SSS</code>.
</div>
</li>
<li class="property">
<div class="name">DATETIME_DATEFORMAT</div>
<div class="summary">
Built-in date format, equivalent to <code>dd MMM YYYY HH:mm:ss,SSS</code>.
</div>
</li>
<li class="property">
<div class="name">ABSOLUTETIME_DATEFORMAT</div>
<div class="summary">
Built-in date format, equivalent to <code>HH:mm:ss,SSS</code>.
</div>
</li>
</ul>
<h4>Constructor</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">PatternLayout</div>
<div class="methodsignature"><code><strong>PatternLayout</strong>(String <em>pattern</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">pattern</code>
<div>
The conversion pattern string to use.
</div>
</li>
</ul>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="xmllayout">
<h3>XmlLayout</h3>
<p class="editions">Editions: <strong>Standard, Production</strong></p>
<p>
Based on log4j's <code>XmlLayout</code>, this layout formats a log message as a
fragment of XML. An example of the format of the fragment is as follows:
</p>
<pre>
&lt;log4javascript:event logger="[default]" timestamp="1201048234203" level="ERROR"&gt;
&lt;log4javascript:message&gt;&lt;![CDATA[Big problem!]]&gt;&lt;/log4javascript:message&gt;
&lt;log4javascript:exception&gt;&lt;![CDATA[Nasty error on line number 1
in file http://log4javascript.org/test.html]]&gt;&lt;/log4javascript:exception&gt;
&lt;/log4javascript:event&gt;
</pre>
<p><strong>Notes</strong></p>
<ul>
<li>
This layout supports batching of log messages when used in an
<code><a href="#ajaxappender">AjaxAppender</a></code>. A batch of
messages is simply concatenated to form a string of several XML
frgaments similar to that above.
</li>
<li>
The <code>&lt;log4javascript:exception&gt;</code> element is only present if an
exception was passed into the original log call.
</li>
<li>
As of version 1.4, timestamps are returned as milliseconds since midnight of
January 1, 1970 rather than seconds as in previous versions. This allows finer
measurement of the time a logging event occurred and is also the JavaScript
<code>Date</code> object's standard measurement.
</li>
<li>
Also as of version 1.4, multiple messages may be specified as separate parameters
in a single logging call. In <code>XmlLayout</code>, multiple messages may be
formatted as a single combined message or may be formated as several
<code>&lt;log4javascript:message&gt;</code> elements inside one
<code>&lt;log4javascript:messages&gt;</code> element as shown below:
<br />
<pre>
&lt;log4javascript:event logger="[default]" timestamp="1201048234203" level="ERROR"&gt;
&lt;log4javascript:messages&gt;
&lt;log4javascript:message&gt;&lt;![CDATA[Big problem!]]&gt;&lt;/log4javascript:message&gt;
&lt;log4javascript:message&gt;&lt;![CDATA[Value of x when this error
occurred: 3]]&gt;&lt;/log4javascript:message&gt;
&lt;/log4javascript:messages&gt;
&lt;log4javascript:exception&gt;&lt;![CDATA[Nasty error on line number 1
in file http://log4javascript.org/test.html]]&gt;&lt;/log4javascript:exception&gt;
&lt;/log4javascript:event&gt;
</pre>
</li>
<li>
As of version 1.3, custom fields may be added to the output. Each field will
add a tag of the following form inside the <code>&lt;log4javascript:event&gt;</code>
tag:
<br />
<pre>
&lt;log4javascript:customfield name="sessionid"&gt;&lt;![CDATA[1234]]&gt;&lt;/log4javascript:customfield&gt;
</pre>
</li>
</ul>
<h4>Constructor</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">XmlLayout</div>
<div class="methodsignature"><code><strong>XmlLayout</strong>([Boolean <em>combineMessages</em>])</code></div>
<ul class="params">
<li class="param">
<code class="paramname">combineMessages</code>
<div>
Whether or not to format multiple log messages as a combined single
<code>&lt;log4javascript:message&gt;</code> element
composed of each individual message separated by line breaks or to include
a <code>&lt;log4javascript:message&gt;</code> element for each message inside
one <code>&lt;log4javascript:messages&gt;</code> element.
If not specified, defaults to <code>true</code>.
</div>
</li>
</ul>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="jsonlayout">
<h3>JsonLayout</h3>
<p class="editions">Editions: <strong>Standard, Production</strong></p>
<p>
Formats a logging event into JavaScript Object Notation (JSON).
JSON is a subset of JavaScript's object literal syntax, meaning that log
messages formatted with this layout can be interpreted directly by JavaScript
and converted into objects. See
<a href="http://json.org/" target="_blank" title="json.org (opens in new window)">json.org</a> for more details
about JSON.
</p>
<p>Example:</p>
<pre>
{
"logger": "[default]",
"timeStamp": 1201048234203,
"level": "ERROR",
"url": "http://log4javascript.org/test.html",
"message": "Big problem!",
"exception": "Nasty error on line number 1 in file
http://log4javascript.org/test.html"
}
</pre>
<p>
The <code>exception</code> property is only present if an exception was passed
into the original log call.
</p>
<p><strong>Notes</strong></p>
<ul>
<li>
This layout supports batching of log messages when used in an
<code><a href="#ajaxappender">AjaxAppender</a></code>. When sent singly
the layout formats the log message as a single JavaScript object literal;
when sent as a batch, the messages are formatted as an array literal whose
elements are log message objects.
</li>
<li>
<p>
As of version 1.3, custom fields may be added to the output. Each field will
add a property of the following form to the main object literal:
</p>
<pre>
"sessionid": 1234
</pre>
</li>
<li>
From version 1.4, the variable names used for log event properties such as
the message, timestamp and exception are specified using the <code>setKeys()</code>
method of <code><a href="#layout">Layout</a></code>.
</li>
<li>
<p>
Also as of version 1.4, multiple messages may be specified as separate parameters
in a single logging call. In <code>JsonLayout</code>, multiple messages may be
formatted as a single combined message or may be formated as an array of messages
as shown below:
</p>
<pre>
{
"logger": "[default]",
"timeStamp": 1201048234203,
"level": "ERROR",
"url": "http://log4javascript.org/test.html",
"message": [
"Big problem!",
"Value of x when this error occurred: 3"
],
"exception": "Nasty error on line number 1 in file
http://log4javascript.org/test.html"
}
</pre>
</li>
</ul>
<h4>Constructor</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">JsonLayout</div>
<div class="methodsignature"><code><strong>JsonLayout</strong>([Boolean <em>readable</em>, Boolean <em>combineMessages</em>])</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">readable</code>
<div>
Whether or not to format each log message with line breaks and tabs.
If not specified, defaults to <code>false</code>.
</div>
</li>
<li class="param">
<code class="paramname">combineMessages</code>
<div>
Whether or not to format multiple log messages as a combined single
<code>message</code> property composed of each individual message separated by line
breaks or to format multiple messages as an array.
If not specified, defaults to <code>true</code>.
</div>
</li>
</ul>
</li>
</ul>
<h4>Methods</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">isReadable</div>
<div class="methodsignature"><code>Boolean <strong>isReadable</strong>()</code></div>
<div class="summary">
Returns whether or not to each log message is formatted with line breaks and tabs.
</div>
<p><strong>Notes</strong></p>
<ul>
<li>
<p>
<code>setReadable</code> has been removed in version 1.4. This property can
be set via the constructor.
</p>
</li>
</ul>
</li>
</ul>
</div>
<div id="httppostdatalayout">
<h3>HttpPostDataLayout</h3>
<p class="editions">Editions: <strong>Standard, Production</strong></p>
<p>
Formats the log message as a simple URL-encoded string from which a simple
server-side script may extract parameters such as the log message, severity
and timestamp. This is the default layout for
<code><a href="#ajaxappender">AjaxAppender</a></code>.
</p>
<h4>Constructor</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">HttpPostDataLayout</div>
<div class="methodsignature"><code><strong>HttpPostDataLayout</strong>()</code></div>
</li>
</ul>
<p><strong>Notes</strong></p>
<ul>
<li>
As of version 1.3, custom fields may be added to the output. Each field will
be added as a parameter to the post data.
</li>
<li>
From version 1.4, the variable names used for log event properties such as
the message, timestamp and exception are specified using the <code>setKeys()</code>
method of <code><a href="#layout">Layout</a></code>.
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
</div>
<div id="enabling">
<h2>Enabling / disabling log4javascript</h2>
<p>
All logging can be enabled or disabled in log4javascript in a number of ways:
</p>
<ul>
<li>
At any time, you can call
<code>log4javascript.setEnabled(<em>enabled</em>)</code>. This will
enable or disable all logging, depending on whether <code>enabled</code>
is set to <code>true</code> or <code>false</code>.
</li>
<li>
<p>
Assign a value to the global variable <code>log4javascript_disabled</code>.
The idea of this is so that you can enable or disable logging for a whole site by
including a JavaScript file in all your pages, and allowing this file to be
included <strong>before</strong> log4javascript.js to guarantee that no logging
can take place without having to alter log4javascript.js itself. Your included
.js file would include a single line such as the following:
</p>
<p>
<code>var log4javascript_disabled = true;</code>
</p>
</li>
<li>
Assign your logger object a value of <code>log4javascript.getNullLogger()</code>.
</li>
<li>
Replace your copy of log4javascript_x.js with stubs/log4javascript_x.js, provided in the
distribution. This file has a stub version of each of the functions and methods
in the log4javascript API and can simply be dropped in in place of the main file.
The compressed version of the stub is typically 15 times smaller than the
compressed version of the main file.
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
<div id="errorhandling">
<h2>log4javascript error handling</h2>
<p>
log4javascript has a single rudimentary logger-like object of its own to handle
messages generated by log4javascript itself. This logger is called <code>LogLog</code>
and is accessed via <code>log4javascript.logLog</code>.
</p>
<div id="loglog">
<h4>Methods</h4>
<ul class="propertieslist">
<li class="method">
<div class="name">setQuietMode</div>
<div class="methodsignature"><code>void <strong>setQuietMode</strong>(Boolean <em>quietMode</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">quietMode</code>
<div>
Whether to turn quiet mode on or off.
</div>
</li>
</ul>
<div class="summary">
Sets whether <code>LogLog</code> is in quiet mode or not. In quiet mode, no
messages sent to <code>LogLog</code> have any visible effect. By default,
quiet mode is switched off.
</div>
</li>
<li class="method">
<div class="name">setAlertAllErrors</div>
<div class="methodsignature"><code>void <strong>setAlertAllErrors</strong>(Boolean <em>alertAllErrors</em>)</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">showAllErrors</code>
<div>
Whether to show all errors or just the first.
</div>
</li>
</ul>
<div class="summary">
Sets how many errors <code>LogLog</code> will display alerts for. By default,
only the first error encountered generates an alert to the user. If you turn
all errors on by supplying <code>true</code> to this method then all errors
will generate alerts.
</div>
</li>
<li class="method">
<div class="name">debug</div>
<div class="methodsignature"><code>void <strong>debug</strong>(String <em>message</em>[, Error <em>exception</em>])</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">message</code>
</li>
<li class="param">
<code class="paramname">exception</code>
[<em>optional</em>]
</li>
</ul>
<div class="summary">
Logs a debugging message to an in-memory list. This implementation is new in version 1.4.
</div>
</li>
<li class="method">
<div class="name">displayDebug</div>
<div class="methodsignature"><code>void <strong>displayDebug</strong>()</code></div>
<div class="summary">
Displays an alert of all debugging messages. This method is new in version 1.4.
</div>
</li>
<li class="method">
<div class="name">warn</div>
<div class="methodsignature"><code>void <strong>warn</strong>(String <em>message</em>[, Error <em>exception</em>])</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">message</code>
</li>
<li class="param">
<code class="paramname">exception</code>
[<em>optional</em>]
</li>
</ul>
<div class="summary">
Currently has no effect.
</div>
</li>
<li class="method">
<div class="name">error</div>
<div class="methodsignature"><code>void <strong>error</strong>(String <em>message</em>[, Error <em>exception</em>])</code></div>
<div class="paramsheading">Parameters:</div>
<ul class="params">
<li class="param">
<code class="paramname">message</code>
</li>
<li class="param">
<code class="paramname">exception</code>
[<em>optional</em>]
</li>
</ul>
<div class="summary">
Generates an alert to the user if and only if the error is the first one
encountered and <code>setAlertAllErrors(true)</code> has not been called.
</div>
</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
</div>
<div id="differences">
<h2>Differences between log4javascript and log4j</h2>
<p>
For the sake of keeping log4javascript as light and useful as possible, many
of the features of log4j that seem over-complex or inappropriate for
JavaScript have not been implemented. These include:
</p>
<ul>
<li>Filters</li>
<li>Configurators</li>
<li>Renderers</li>
</ul>
<p class="linktotop">
<a href="#container">Top</a>
</p>
</div>
</div>
<div id="footer">
<span class="externallinkinfo">
<strong>NB.</strong> All external links open in a new window.
</span>
Written by Tim Down. <a href="mailto:tim@log4javascript.org">tim@log4javascript.org</a>
<br />
log4javascript is distributed under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html"
title="Apache License, Version 2.0 (opens in new window)" target="_blank">Apache License,
Version 2.0</a>
</div>
</div>
</body>
</html>