Interacting With Log4J

Some components, both provided by iWay and your own, may make use of third party libraries that log with Log4J. In order to capture these logs, iWay initializes the Log4J system as the server starts. If the server finds a file named "log4j.properties" in its current working directory, it will try to configure Log4J with this file. If no such file is found, we configure Log4J with the root logger at INFO level and an appender that routes Log4J messages to the server's own log.

For example, the NHTTP extension uses HttpClient from Apache Commons, which traces with Log4J. To see HttpClient's wire header and context messages, we could use a log4j.properties file like this:

log4j.rootLogger=INFO, xd
log4j.appender.xd=com.ibi.logging.XDLog4jAppender
log4j.appender.xd.mapDebugToDeep=true
log4j.appender.xd.layout=org.apache.log4j.PatternLayout
log4j.appender.xd.layout.ConversionPattern=[%C{1} - %M()] - %m
log4j.logger.httpclient.wire.header=DEBUG
#log4j.logger.org.apache.commons.httpclient=DEBUG

Here, we first set the root logger to INFO level and add the XDLog4JAppender. The .xd on the definition of the rootLogger is required. Since most applications that use Log4J seem to treat DEBUG level as the server does its DEEP level, the mapDebugToDeep option on the appender writes Log4J DEBUG messages to iWay's DEEP level. Finally, we set up the appender with a layout pattern that prints class, method, and message; this mirrors the format in iWay.

The last two lines control specific Log4J loggers created by HttpClient. For details on this, check documentation for the relevant component.

Log4J is classed by iWay as an external log system, and is turned on in the server by setting the external level. You can do this by using the set command from the shell.


iWay Software