logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter DePasquale <peter.depasqu...@gmail.com>
Subject Simple (?) question about logging behavior (additive issue?)
Date Mon, 25 Mar 2013 17:25:53 GMT
Hi,

I've been trying to track down some failure to log in my Tomcat
application. In doing so, I've written a small Test class in which I log
.entry(), .exit(), .trace(), and error() events (source code is below).

I've also copied the log4j2.xml file and the output files created by the
logging system (beta4). What I don't understand is why all TRACE and ERROR
messages end up only in the trace file, and the error file is empty.

My understanding is that the trace and error messages would be logged in
the trace file. However, it was my intention to log error events in the
error file created by the root logger.  Why are error events not being
passed to the root, or why is root not writing them out? If additivity is
implicitly enabled, should not all the events be passed to the root logger,
and that root would only process those error events passed to it?

log4j2.xml
========
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="debug">
<properties>
<property
name="errorLog">${sys:catalina.base}/logs/comtor-log-errors.txt</property>
<property
name="traceLog">${sys:catalina.base}/logs/comtor-log-trace.txt</property>
</properties>

<appenders>
<File name="errorFile" fileName="${errorLog}" suppressExceptions="false"
append="false">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %p %C.%M [%t] - %msg%n"/>
</File>

<File name="traceFile" fileName="${traceLog}" suppressExceptions="false"
append="false">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %p %C.%M [%t] - %msg%n"/>
</File>
</appenders>
 <loggers>
<root level="error">
<appender-ref ref="errorFile"/>
</root>

<logger name="Test" level="trace">
<appender-ref ref="traceFile"/>
</logger>

</loggers>
</configuration>

Test.java
=======
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

public class Test extends HttpServlet {
private static Logger logger = LogManager.getLogger(Test.class.getName());

/**
 * Called by the server (via the service method) to allow a servlet to
handle a GET request.
 * See {@link
http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServlet.html#doGet(
 *       javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)}
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
logger.entry();
logger.error("Error message.");
logger.trace("Trace message.");
logger.exit();
}
}

comtor-log-trace.txt
==============
$ more comtor-log-trace.txt
2013-03-25 13:23:11 TRACE Test.doGet [http-bio-80-exec-55] -  entry
2013-03-25 13:23:11 ERROR Test.doGet [http-bio-80-exec-55] - Error message.
2013-03-25 13:23:11 TRACE Test.doGet [http-bio-80-exec-55] - Trace message.
2013-03-25 13:23:11 TRACE Test.doGet [http-bio-80-exec-55] -  exit

comtor-log-error.txt
==============
<empty file>

-- 
Peter J. DePasquale, Ph.D.
Department of Computer Science
The College of New Jersey
(e) depasqua [at] tcnj [dot] edu
(p) 609-771-2806
(f) 609-637-5190
(o) Holman Hall - Room 238
(l) Holman Hall - Room 255

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message