Download NetBeans!

20050706 Wednesday July 06, 2005

Lumbermill: Log4j Messaging in NetBeans IDE

In Log4j, Wicket, Tomcat, and NetBeans IDE, I took my first tentative steps in the land of Log4j. Today I found that someone had left a comment at the end of that blog entry, telling me about something I hadn't heard of yet (which is further evidence of the usefulness of blogging) -- a handy GUI that displays all the Log4j messages in NetBeans IDE: Lumbermill plug-in for NetBeans. It's really really really very cool. Really. Here's a screenshot of what it looked like for me, after I'd deployed yet another Wicket sample application:

However, it took a bit of work to set up. Getting the plug-in is easy, just go to the NetBeans-Lumbermill site. Then, if you haven't already done so, set up Log4j exactly as described here.

After that, though, you'll need to know a little bit more about the log4j.properties file (everything I know about this I learnt here), otherwise you'll still not have found what you're looking for. This file, which -- if you've followed the instructions here -- is found in Tomcat's common/classes folder, has a log4j.rootLogger entry, right at the top. The rest of the file consists of entries that start like this: log4j.appender. It is important to know that each of the appenders is defined by the log4j.rootLogger entry. So, for example, in this log4j.properties file, you'll find that an appender with the name "R" has been defined. Subsequently, the file contains entries such as the following:

log4j.appender.R.File=C:/.netbeans/4.1/jakarta-tomcat-5.5.7_base/logs/tomcat.log

This tells Log4j where to put the output of the R appender, which is supplied by org.apache.log4j.DailyRollingFileAppender. For Lumbermill, I've learnt, you need the following entries in the log4j.properties file:

log4j.appender.LogServer=org.apache.log4j.net.SocketAppender
log4j.appender.LogServer.Port=4445
log4j.appender.LogServer.RemoteHost=localhost

But, to activate the above entries, you'd need to add the appender to the log4j.rootLogger entry. (And, to activate the output of logging message to the Output window for this log4j.properties file, you'd need to append "A1" to the same entry too.) So now my log4j.rootLogger entry looks as follows:

log4j.rootLogger=INFO, R, A1, LogServer

After making these changes to the log4j.properties file, I not only received Log4j messages in the IDE's Output window, but also in the Lumbermill GUI. (And, on top of that, the Log4j messages appeared in my log file too.) Pretty cool. And remember that I'm only using it to view my local logging messages -- using the log4j.appender.LogServer.RemoteHost entry, I can also view my remote Log4j messaging. Lumbermill rocks. Now, apparently, there's also something called Sawmill? Hmmm. Let's look into that...

Jul 06 2005, 03:29:11 AM PDT Permalink