I would like to have 2 appenders: RollingFileAppender, ConsoleAppender. It should work on JBoss and Tomcat at least. If log4j.properties is modified, the new settings should be picked up dynamically.
Here's what my log4j.properties file looks like: log4j.logger.com.pocolap=DEBUG log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.category.com.pocolap=, R log4j.appender.R.layout.ConversionPattern=[%d] %p %x - %m%n log4j.appender.R.MaxBackupIndex=1 log4j.appender.R.File=C\:\\pocolapDB\\pocolaplog.txt log4j.appender.R.MaxFileSize=100KB log4j.appender.R.layout=org.apache.log4j.PatternLayout
This how my init code looks like:
My problem is when the app is deployed on Tomcat and I modify log4j.properties. It is watching the directory but It ends up having zero appenders 'log4j:WARN No appenders found for logger'. How can I have atleast the RollingFileAppender (if not ConsoleAppender) ?
These two lines conflict. logger is the new term for the old term category. So, they are both trying to configure the logger/category for com.pocolap. The logger one probably wins, and it doesnt' have an appender associated with it:
log4j.logger.com.pocolap=DEBUG log4j.category.com.pocolap=, R
Not sure why you're configuring the console appender in code and not in the properties file.
Thank you very much for your reply. It worked as expected. I am configuring ConsoleAppender manually and not in properties file, because JBoss already has ConsoleAppender configured. So it conflicts and I get an error 'Console Stream is looping'. If you have any better suggestion to make ConsoleAppender work on JBoss as well as Tomcat. Please let me know.
I don't use JBoss, so I don't know the issues involved. Are you trying to see the JBoss logging or some of your own logging that is going only to the root logger?
Quick google shows some people say configuring console appender with JBoss is pretty tricky. Others say to modify JBoss's log4j.xml in the directory $jboss/server/default/conf. Since you're using the properties format I assume you're creating a separate config file.
I figured this out. This is what my log4j looks like:
This gives logger messages once on Tomcat and twice on JBoss console. Because JBoss already has a ConsoleAppender configured. I'll live with this for now. (Also no more manual configuring ConsoleAppender in the code)
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop