47 lines
11 KiB
HTML
47 lines
11 KiB
HTML
<!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"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>System.Log.Handler.Log4jXML</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
|
|
window.onload = function () {pageLoad();setSynopsis("mini_System-Log-Handler-Log4jXML.html");};
|
|
//]]>
|
|
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">hslogger-1.2.8: Versatile logging framework</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Copyright</th><td>Copyright (C) 2007-2011 John Goerzen</td></tr><tr><th>License</th><td>BSD3</td></tr><tr><th>Maintainer</th><td>bjorn.buckwalter@gmail.com</td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Portability</th><td>GHC only?</td></tr><tr><th>Safe Haskell</th><td>Safe</td></tr><tr><th>Language</th><td>Haskell98</td></tr></table><p class="caption">System.Log.Handler.Log4jXML</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Introduction</a><ul><li><a href="#g:2">Handlers with hslogger levels </a></li><li><a href="#g:3">Handlers with log4j levels</a></li></ul></li><li><a href="#g:4">Java install process</a></li><li><a href="#g:5">Chainsaw setup</a></li><li><a href="#g:6">Example usage</a></li><li><a href="#g:7">References</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>log4j[1] XMLLayout log handlers.</p><p>Written by Bjorn Buckwalter, bjorn.buckwalter@gmail.com</p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><a href="#v:log4jStreamHandler">log4jStreamHandler</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="System-Log.html#t:Priority">Priority</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> (<a href="System-Log-Handler-Simple.html#t:GenericHandler">GenericHandler</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a>)</li><li class="src short"><a href="#v:log4jFileHandler">log4jFileHandler</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="System-Log.html#t:Priority">Priority</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> (<a href="System-Log-Handler-Simple.html#t:GenericHandler">GenericHandler</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a>)</li><li class="src short"><a href="#v:log4jStreamHandler-39-">log4jStreamHandler'</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="System-Log.html#t:Priority">Priority</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> (<a href="System-Log-Handler-Simple.html#t:GenericHandler">GenericHandler</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a>)</li><li class="src short"><a href="#v:log4jFileHandler-39-">log4jFileHandler'</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="System-Log.html#t:Priority">Priority</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> (<a href="System-Log-Handler-Simple.html#t:GenericHandler">GenericHandler</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a>)</li></ul></div><div id="interface"><h1 id="g:1">Introduction</h1><div class="doc"><p>This module provides handlers for hslogger that are
|
|
compatible with log4j's XMLLayout. In particular log messages
|
|
created by the handlers can be published directly to the GUI-based
|
|
log viewer Chainsaw v2[2].</p><p>The set of log levels in hslogger is richer than the basic set
|
|
of log4j levels. Two sets of handlers are provided with hslogger4j,
|
|
one which produces logs with hslogger's levels and one which
|
|
"demotes" them to the basic log4j levels. If full hslogger
|
|
levels are used some Java installation (see below) is necessary
|
|
to make Chainsaw aware of them.</p><p>Usage of the handlers in hslogger4j is analoguous to usage of
|
|
the <code><a href="System-Log-Handler-Simple.html#t:StreamHandler">StreamHandler</a></code> and
|
|
<code><a href="System-Log-Handler-Simple.html#t:FileHandler">FileHandler</a></code> in <a href="System-Log-Handler-Simple.html">System.Log.Handler.Simple</a>.
|
|
The following handlers are provided: </p></div><h2 id="g:2">Handlers with hslogger levels </h2><div class="top"><p class="src"><a name="v:log4jStreamHandler" class="def">log4jStreamHandler</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="System-Log.html#t:Priority">Priority</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> (<a href="System-Log-Handler-Simple.html#t:GenericHandler">GenericHandler</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a>)</p><div class="doc"><p>Create a stream log handler that uses hslogger priorities.</p></div></div><div class="top"><p class="src"><a name="v:log4jFileHandler" class="def">log4jFileHandler</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="System-Log.html#t:Priority">Priority</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> (<a href="System-Log-Handler-Simple.html#t:GenericHandler">GenericHandler</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a>)</p><div class="doc"><p>Create a file log handler that uses hslogger priorities.</p></div></div><h2 id="g:3">Handlers with log4j levels</h2><div class="top"><p class="src"><a name="v:log4jStreamHandler-39-" class="def">log4jStreamHandler'</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="System-Log.html#t:Priority">Priority</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> (<a href="System-Log-Handler-Simple.html#t:GenericHandler">GenericHandler</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a>)</p><div class="doc"><p>Create a stream log handler that uses log4j levels (priorities). The
|
|
priorities of messages are shoehorned into log4j levels as follows:</p><pre> DEBUG -> DEBUG
|
|
INFO, NOTICE -> INFO
|
|
WARNING -> WARN
|
|
ERROR, CRITICAL, ALERT -> ERROR
|
|
EMERGENCY -> FATAL
|
|
</pre><p>This is useful when the log will only be consumed by log4j tools and
|
|
you don't want to go out of your way transforming the log or configuring
|
|
the tools. </p></div></div><div class="top"><p class="src"><a name="v:log4jFileHandler-39-" class="def">log4jFileHandler'</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="System-Log.html#t:Priority">Priority</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> (<a href="System-Log-Handler-Simple.html#t:GenericHandler">GenericHandler</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a>)</p><div class="doc"><p>Create a file log handler that uses log4j levels (see
|
|
<code><a href="System-Log-Handler-Log4jXML.html#v:log4jStreamHandler-39-">log4jStreamHandler'</a></code> for mappings). </p></div></div><h1 id="g:4">Java install process</h1><div class="doc"><p>This is only necessary if you want to use the hslogger levels.</p><p>Add <code>hslogger4j.jar</code> from <code>contrib/java</code> to your classpath.
|
|
To use you will also need to have the jars <code>log4j-1.3alpha-7.jar</code>
|
|
and <code>log4j-xml-1.3alpha-7.jar</code> that are distributed with Chainsaw
|
|
on your classpath.</p><p>(On Mac OS X I added all three jars to <code>~/Library/Java/Extensions</code>.
|
|
It seems that it is not sufficient that Chainsaw already includes
|
|
its jars in the classpath when launching - perhaps the plugin
|
|
classloader does not inherit Chainsaw's classpath. Adding the
|
|
jars to <code>~/.chainsaw/plugins</code> wouldn't work either.)</p><p>If for whatever reason you have to rebuild the hslogger4j jar
|
|
just run <code>ant</code>[3] in the <code>contrib/java</code> directory. The new jar
|
|
will be created in the <code>contrib/java/dist</code> directory. The Java
|
|
source code is copyright The Apache Software Foundation and
|
|
licensed under the Apache Licence version 2.0. </p></div><h1 id="g:5">Chainsaw setup</h1><div class="doc"><p>If you are only using the basic log4j levels just use
|
|
Chainsaw's regular facilities to browse logs or listen for log
|
|
messages (e.g. <code>XMLSocketReceiver</code>).</p><p>If you want to use the hslogger levels the easiest way to set
|
|
up Chainsaw is to load the plugins in <code>hslogger4j-plugins.xml</code>
|
|
in <code>contrib/java</code> when launching Chainsaw. Two receivers will
|
|
be defined, one that listens for logmessages and one for reading
|
|
log files. Edit the properties of those receivers as needed
|
|
(e.g. <code>port</code>, <code>fileURL</code>) and restart them. You will also want
|
|
to modify Chainsaw's formatting preferences to display levels
|
|
as text instead of icons. </p></div><h1 id="g:6">Example usage</h1><div class="doc"><p>In the IO monad:</p><pre>lh2 <- log4jFileHandler "log.xml" DEBUG
|
|
updateGlobalLogger rootLoggerName (addHandler lh2)</pre><pre>h <- connectTo "localhost" (PortNumber 4448)
|
|
lh <- log4jStreamHandler h NOTICE
|
|
updateGlobalLogger rootLoggerName (addHandler lh)</pre></div><h1 id="g:7">References</h1><div class="doc"><ol><li><p><a href="http://logging.apache.org/log4j/">http://logging.apache.org/log4j/</a></p><ol><li><a href="http://logging.apache.org/chainsaw/">http://logging.apache.org/chainsaw/</a></li><li><a href="http://ant.apache.org/">http://ant.apache.org/</a></li></ol></li></ol></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.16.0</p></div></body></html> |