Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Fun with Log4J and JBoss

I've had the pleasure of working with JBoss (3.2.5) and an AppFuse-based application for the past week. It was fairly easy to setup thanks to Rick Hightower's instructions. AppFuse uses commons logging (like many of its open-source dependencies), but uses log4j to control what gets printed to where. By default, it changes Hibernate and Spring to use WARN and the application classes to use DEBUG. For most containers, this works great. Drop in the WAR, or package it in an EAR and voila - your logging statements show up in the console. Not so with JBoss. Spring and Hibernate use INFO and I can't get any debug statements to show from my classes.

I shouda known this would be a pain since Rick wrote "Setting up logging is a pain in JBoss. Don't mess with the console log... it misbehaves. Create a file logger and tail it.". Is this the best practice for logging with Log4J in JBoss?

You'd think printing to the console would be easy. This wiki page even makes it look easy: change your log4j.properties to log4j.xml and add a <class-loading> snippet to your jboss-web.xml. Unfortunately, I get this nice error message:

00:21:17,593 WARN  [DeploymentInfo] Only the root deployment can set the loader repository, ingoring
 config=LoaderRepositoryConfig(repositoryName: log4j.config:loader=appfuse.war, repository
ClassName: org.jboss.mx.loading.HeirarchicalLoaderRepository3, configParserClassName: org.jboss.mx.l
oading.HeirarchicalLoaderRepository3ConfigParser, repositoryConfig: java2ParentDelegation=false)

Any ideas are appreciated - it seems wrong that I have to write to file just to tail it so I get the same console behavior I get with other servers.

Posted in Java at Oct 29 2004, 12:12:15 AM MDT 7 Comments
Comments:

!Hi Matt, I had the same problem, the JBOSS log4j conf file has a threshold set to INFO. Because there is already a console appender added to the root logger JBOSS does not allow another Console Appender to be added to the root Logger. You get a message like "console stream looping" . What I did was set the ConsoleAppender threshold to Debug programatically {{{ boolean isConsoleAppenderInstalled = false; while(en.hasMoreElements()) { Appender appender = (Appender)en.nextElement(); if(appender instanceof ConsoleAppender) { if(((ConsoleAppender)appender).getThreshold().isGreaterOrEqual(Level.INFO)) { ((ConsoleAppender)appender).setThreshold(Level.DEBUG); isConsoleAppenderInstalled =true; } } } if(!isConsoleAppenderInstalled) { ConsoleAppender ca = new ConsoleAppender(new PatternLayout(consolePattern),ConsoleAppender.SYSTEM_OUT); ca.setThreshold(Level.DEBUG); LogManager.getRootLogger().addAppender(rf); } DOMConfigurator.configure(...); }}} And in the log4j just set your categories up with a particular level Example {{{ <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"> <category name="org.quartz"> <priority value="INFO"/> </category> <!-- Limit the org.apache category to INFO as its DEBUG is verbose --> <category name="net.sf.hibernate"> <priority value="INFO"/> </category> </log4j:configuration> }}} Danny

Posted by Danny on October 29, 2004 at 08:28 AM MDT #

Why not set up your logging to go to a socket and run chainsaw v2 to monitor it? That way you can filter out the logging that you don't want to see from the viewer perspective without actually loosing the more detailed (or other logger) log messages that you may find you need later. I find that so much easier than wading through the console output. Also, I don't know if JBoss has one available, but try writing a JSP/Servlet that can monitor and control logging programatically. If you don't want to write one, you could use LogWeb

Posted by Tim on October 29, 2004 at 01:05 PM MDT #

!Chainsaw V2 can also tail log files using a LogFilePatternReceiver. Here's how:\\ \\ Get Chainsaw (available via WebStart) [here|http://logging.apache.org/log4j/docs/chainsaw.html]. Modify the below-provided xml as needed (add other 'plugin' nodes for each file you want to view/tail in Chainsaw) and save as chainsaw.xml Here's a [link|http://cvs.apache.org/viewcvs.cgi/logging-log4j/src/java/org/apache/log4j/varia/LogFilePatternReceiver.java?rev=1.19&view=auto] to the LogFilePatternReceiver javadoc, describing the receiver and the params (including 'logFormat' keywords). Inside Chainsaw, select: view-show application wide preferences - enter the URL of this chainsaw.xml in the 'automatic configuration URL' field - restart chainsaw chainsaw.xml: {{{ <?xml version="1.0" encoding="UTF-8" ?> <!DOCENGINE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true"> <plugin name="logFileReceiver" class="org.apache.log4j.varia.LogFilePatternReceiver"> <param name="fileURL" value="file:///c:/downloads/jboss/server/default/log/server.log" /> <param name="timestampFormat" value="HH:mm:ss,SSS"/> <param name="logFormat" value="TIMESTAMP LEVEL [LOGGER] MESSAGE"/> <param name="name" value="jbossReceiver" /> <param name="tailing" value="true" /> </plugin> <root> <level value="debug"/> </root> </log4j:configuration> }}} Once you restart Chainsaw, you'll get a tab for each log file. Double-click on a column in Chainsaw to sort on the column. There's a tutorial available from Chainsaw's Welcome page. Feel free to email myself or the log4j-users mailing list with questions.

Posted by Scott on October 29, 2004 at 02:14 PM MDT #

Back in JBoss 3.x, I had to use one of the jboss-specific ear deployment descriptor files to make sure that my app had its own classloaded copy of Log4j -- that way, there wasn't any conflict between my app's config and JBoss's own. (Basically, giving the EAR its very own classloader so it didn't have to mess with JBoss's copies).

Posted by Nathaniel on November 11, 2004 at 07:09 PM MST #

See code in this linked message: http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=63&t=001436 Although my question was never answered, the code supplied shows a way to accomplish a classloaded copy of Log4j as mentioned above. Not the prettiest thing in the world, but it opens up some uses across multiple web apps running on the same server.

Posted by 12.5.150.254 on April 21, 2005 at 06:54 PM MDT #

I also found a related link: http://java.joycoding.com/java-archive/667/26667-1.html, maybe it's useful...

Posted by java developer on November 13, 2008 at 03:51 AM MST #

I also found a related link: http://java.joycoding.com/java-archive/667/26667-1.html, maybe it's useful...

Posted by developer on November 13, 2008 at 03:52 AM MST #

Post a Comment:
  • HTML Syntax: Allowed