Adjusting Logging from the JMX Console


We've seen JBoss watch the log4j.xml file and reconfigure log4j when the file changes. That's not the only way to change log levels in the system. All services in JBoss are represented by MBeans that you can interact with remotely. The easiest way to do that is through the JMX Console application. We'll just touch on the JMX Console here, but in the next chapter we'll go much further into how it works. For now, let's see how we can adjust the logging level of a category.

How do I do that?

To get to the JMX Console you need to go to http://localhost:8080/ in your browser. Click the JMX Console and find the jboss.system domain section. To access the log4j service, you should click on the service=Logging,type=Log4jService link. You'll see a list of MBean attributes and operations. You are looking for the getLoggerLevel operation, which looks like Figure 6-1.

Developer's Notebook 6-1. MBean operations for getLoggerLevel


The getLoggerLevel operation takes the name of a logging category and returns the level of that category. To see the log level for the com.oreilly.jbossnotebook.todo category, enter the category name and click the Invoke button. If you still have the category set to DEBUG or INFO, you will see that value returned. If you don't see any return value, you don't have the level set on the category.

The setLoggingLevel operation can adjust the log level of a category at runtime. Enter the same category and set the level parameter to ERROR. Don't worry if you don't see any output other than "Operation completed successfully without a return value." You can invoke the getLoggerLevel operation again to verify the level is correct. Checking the logfile is a great sanity check, too.


Note: Setting log levels in the JMX Console doesn't modify log4j.xml. Changes made this way will be lost if the server resets, or the next time the log4j.xml file is loaded.

What just happened?

You used the JMX Console to get and set the log levels for the ToDo application. This is very useful when you have limited access to the application server machine. Going through the console can be easier than editing a configuration file on a remote machine. It's also useful when you want to temporarily play with log levels without changing the configuration state in log4j.xml.



JBoss. A Developer's Notebook
JBoss: A Developers Notebook
ISBN: 0596100078
EAN: 2147483647
Year: 2003
Pages: 106

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net