logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remko Popma <rem...@yahoo.com>
Subject Re: Simple test case for logging uner a tomcat web app
Date Wed, 24 Apr 2013 05:39:51 GMT
Peter,

I don't have Tomcat installed but I was able to reproduce the problem in a standalone test
using your configuration.

There is a couple of things I found.
First, File appenders have these configuration settings by default:
bufferedIO="true" and immediateFlush="false".

This means that messages will not be written to disk until the buffer is full.
I think we should improved the documentation for this and I've filed this JIRA ticket:
https://issues.apache.org/jira/browse/LOG4J2-218


Second, looks like you found a bug!
Even after adding immediateFlush="true" to the File config, the trace-log.txt file is empty.

I don't understand the underlying cause yet, but if the config has a named logger 
and no root logger, the named logger internally ends up with no Appender objects.
I've filed another JIRA for this:
https://issues.apache.org/jira/browse/LOG4J2-219


Workaround:
1. Specify immediateFlush="true" in the File appender config
2. Replace the named logger with a root logger configuration

The config below worked for me. 
(In my standalone test, that is. I haven't installed Tomcat.
Can you try this and let me know if there is any problem?)

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="warn">
	<appenders>
		<File name="tracelog" fileName="${sys:catalina.base}/logs/trace-log.txt" 
				immediateFlush="true" append="false">
			<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
		</File>
	</appenders>
	
	<loggers>
		<root level="trace">
			<appender-ref ref="tracelog"/>
		</root>
	</loggers>
</configuration>

Sent from my iPhone

On 2013/04/24, at 10:13, Peter DePasquale <peter.depasquale@gmail.com> wrote:

> I continue to struggle achieving basic logging results under my web app
> under tomcat. It seemed to work months ago, but when I upgraded to the
> latest beta logging failed.
> 
> I returned to examine my config and failed to solve the problem. I emailed
> this list about this and I received no response. After asking for help a
> second time Ralph suggested I post code.
> 
> Thus, I have attempted to simplify my problem down and post a VERY SIMPLE
> web app that attempts to do trace and error logging.  I was trying to get
> this into to separate files, but I'm learning that that's apparently not
> really the model I should embrace as a logging novice.
> 
> Now I have trace logging going to one file. However, despite the app
> running successfully, an empty log file is created.  I can't determine what
> I'm doing wrong and seek help one last time on my inability to grasp the
> correct form for logging of this nature.
> 
> I really don't want to go back to println statements, but if I can't make
> this work, I will. My application is my academic research project and I'm
> delayed in developing new features because I got mired down in trying to
> solve these issues so that I can support logging in my app (seemed smart at
> the time).
> 
> Regardless, the code is posted here at github. I welcome any help that
> anyone can provide by download or visual inspection. I am posting this and
> setting away for the night as I can not work on this today any longer.
> 
> My setup is a Mac OSX 10.6 running Tomcat 7.0.37 locally. Beyond the basic
> apps that Tomcat is preloaded with, this is the only running app.
> 
> https://github.com/depasqua/log4j2tester
> 
> Thanks. Sorry for my vent.
> -- 
> 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, 7-Bit, 0 bytes)
View raw message