[Solved] log4j not logging
Before asking, I looked at several posts (1, 2, 3, 4 and 5) which seemed related, and tried out everything which seemed relevant - still no success.
I have a pretty straightforward log4j.xml file:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="QooxdooServletTestBedLog" class="org.apache.log4j.FileAppender">
<param name="File" value="/var/log/qxapp.log" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.SimpleLayout" />
</appender>
<appender name="Console" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="DEBUG" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd} %-5p - %r - %c - %t - %m\n" />
</layout>
</appender>
<logger name="com.test.jsonrpc">
<level value="debug" />
<appender-ref ref="Console" />
</logger>
<logger name="com.test.test">
<level value="debug" />
<appender-ref ref="Console" />
</logger>
<root>
<priority value="debug" />
<appender-ref ref="Console" />
</root>
</log4j:configuration>
Momentarily it's somewhat garbled because I first tried with a file, then with a console appender, and left all loggers and the like in it.
The file is loaded via a org.springframework.util.Log4jConfigurer configured in applicationContext.xml:
Code:
<bean id="log4jInitialization"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
<property name="targetMethod" value="initLogging" />
<property name="arguments">
<list>
<value>file:/WEB-INF/log4j.xml</value>
</list>
</property>
</bean>
I know for sure the file is read, i.e. that the value file:/WEB-INF/log4j.xml is right, because if I change it to something invalid I get a FileNotFoundException in tomcat's logs.
By analyzing the stack trace and the behavior of the application in case a bad log4j.xml path is passed to the configurer, I got pretty confident that the configurer gets called before the servlet which does the logging gets called - it I set a breakpoint in the servlet, when running with the debugger, I never reach it, if the path to log4j.xml is not right.
In my code, I have the following:
Code:
Logger logger = Logger.getLogger("com.test.jsonrpc.JSONRPCServlet");
logger.debug("Received request: " + requestString);
and many more logging statements. I temporarily replaced this.getClass().getName() with a string constant just to be sure about what's passed to getLogger(), but I also tried passing the class name, with no success.
I get no exception at all. The code which actually does something works without a glitch. Part of it does also logging and is packed inside a bean which is loaded via the same applicationContext.xml where the log configurer is configured. Nevertheless, I can't see any trace of the log statements outputting something, neither in /var/log/qxapp.log, nor in tomcat's own logs, no matter which appender I refer in the <logger/> elements or in the <root/> element inside log4j.xml.
I created the file /var/log/qxapp.log in advance, and set tomcat6's group and owner on it. Before that, I didn't create a file, but configured log4j.xml to create the log file inside tomcat's logs directory. The log file was not created.
I'm running tomcat6 on karmic. I replaced the openjdk jvm with Sun's jvm, since tomcat wouldn't start in remote debug mode using openjdk.
What am I doing wrong? Logging seems the only hurdle I have to take before being able to actually start working on the application to be developed.
I suppose you had tomcat's security disabled?
Or the policy files already edited? 'Cause otherwise there's no way of working, other than a serious security flaw in tomcat.