Forum Controls
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

NetBeans 6: Matisse Updates

NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed.

Introduction to Groovy Part 3

In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.

Easier Custom Components with Swing Fuse

Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.

Benchmark Analysis: Guice vs Spring

Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
Replies: 1 - Pages: 1  
Threads: [ Previous | Next ]
  Click to reply to this thread Reply

Automatic Remote Logging Management via JMX

At 12:16 AM on Jan 9, 2008, Khoo Chen Shiang wrote:

It all started weeks ago, where I have accidentally discovered a “hidden JDK 5 treasure” (from Daniel Fuch's blogs at http://blogs.sun.com/jmxetc/) , called java.lang.instrument, a Java package that provides services that allowing Java language agents to instrument programs running on the JVM. Most people use it for profiling, or pre-instrument purpose.

So, I decided to create a Automatic Remote Logging Management Agent, that able wrap any Java application that use apache log4j for logging, and provide us the following functionalities:

* Abilities to change log level (debug, info, warning, error) on any configured logger dynamically without restart.
* Abilities to locate any configured log output files.
* Abilities to browse (either head, or tail, or from any filePointer) any configured log files.

Base on requirements above, I come out JMXMBean interface below:
public interface RemoteLoggingMBean {
 
  public void activateDebug(String loggerName);
  public void activateInfo(String loggerName);
  public void activateWarning(String loggerName);
  public void activateError(String loggerName);
    /**
     * Retrieve current configured log output files base on given logger.
     * The system will only return log files with  the following appender
     * org.apache.log4j.DailyRollingFileAppender, org.apache.log4j.FileAppender
     * org.apache.log4j.RollingFileAppender;
     * @param loggerName
     * @return Array of file name with relataive file path points to current running directory.
    */
  public String[] retrieveCurrentConfiguredLogFiles(String loggerName);
 
 
    /**
     * Similar to Unix head command, read a text file forward from the beggining
     * of the file till it reaches line limit, or EOF
     * @param fileName the logFileName.
     * @param linesToRead, Number of line to be read.
     * @return JMX CompositeData with the structure of StartFilePointer (SimpleType.Long), 
     * EndFilePointer(SimpleType.Long), LogMessages(SimpleType.String)
     * @throws java.io.IOException
    */
  public CompositeData headLog(String fileName, int linesToRead) throws OpenDataException, IOException;
  public CompositeData headLog(String fileName, int linesToRead, long fromFilePointer) throws OpenDataException, IOException;
  public CompositeData tailLog(String fileName, int linesToRead) throws OpenDataException, IOException;
  public CompositeData tailLog(String fileName, int linesToRead, long fromFilePointer) throws OpenDataException, IOException;
}


The rest of code is delivered by using various JMX and Apache Log 4J API, which I am not going to discuss here, as this is obviously not JMX nor Java Logging tutorial.

If u interest, u could download the whole project source from here. Is not under any copy write protection. U are welcome to download it, modify it, even change the author name, use it or distribute it to anyone.

Anywhere, back to topic. To use the wrapper on any Java application that use Apache Log4J for logging, follows steps below:

1. Either download the binary RemoteJMXLoggingAgent.jar from here or build it from the source
2. Put the binary to your application class path, make sure it sit together with log4j.jar
3. Append the line at your Java Application startup script

"-javaagent:(deploy directory)/RemoteJMXLoggingAgent.jar
-Drmi.agent.port=AnyRMIPort (optional, default=3000)"

That's it, u application is now able to offer above Remote Logging management functionalities via JMX. To test this, open jconsole from any PC, and connect your remote application via the JMX URL below:
service:jmx:rmi:///jndi/rmi://hostname:rmi_port/remoteLoggerAgent

The Mbean on managing your application logger is called "org.coolboy.RemoteLoggingManager", have fun!
1 . At 1:04 AM on Jan 22, 2008, babar wrote:
  Click to reply to this thread Reply

Re: Automatic Remote Logging Management via JMX

Useful tip, thanks.
Java Tutorial

thread.rss_message