Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Cut down on logging errors with Jylog

Separate logging from coding for error-free and flexible event logging

  • Print
  • Feedback
With the addition of the Logging API in Sun's JDK 1.4 (Merlin) beta release, the importance of logging is evident. Logging helps you find code failure points and helps you trace variable values at various locations in your code.

The current approach to logging is to write log statements at important points in your code; those statements essentially invoke some logging library to format the log data. However, this approach is prone to common programming errors resulting from overlooked or misused log statements. So, instead of aiding in debugging, the logging code itself needs debugging. In addition, log statements provide a static log generating system in which you cannot add a new log statement without modifying the source.

Assume that, after writing an algorithm, you need to observe some variable's value at certain code points. One solution uses a debugger and sets breakpoints, and then sets watches (when debugging halts the execution, values of selected variables display in a watch window) at those points. This technique slows the process; every time the breakpoint is hit, you must check the current values and press a button to resume execution. If the code executes a few hundred times, debugging becomes a programmer's nightmare, especially with a multithreaded program.

What is Jylog?

Jylog, an open source logging tool I built with the Java Platform Debugger Architecture (JPDA) SDK 1.3, generates logs for Java programs at runtime. It completely separates the task of logging from coding, eliminating logging errors in your code. You can configure whatever you need logged in Jylog's Swing-based GUI. You can also store this information in an XML file for reuse.

Jylog uses the log configuration to suspend the program execution at certain times and extracts the necessary information (such as method entry and exit, local variables, instance variables, or method parameters) from the JVM at runtime. Since it extracts the information from JVM stacks, that information is guaranteed to be complete and correct. With this information, Jylog prepares a thread-aware XML log tree in which the execution's thread trace is logged separately.

Here is a summary of Jylog's main features:

  • Does not modify the application source or binaries.
  • Works with JVM, KVM, and applets.
  • Extracts logs from the JVM at runtime.
  • Logs all necessary information, like timestamp, thread ID, code line, class name, and method name.
  • Logs values of any local variable, instance variable, or any custom message at any code line.
  • Logs all caught and uncaught exceptions automatically.
  • Fully supports multithreading. Logs all threads separately along XML log tree branches.
  • Is location independent; the debugged JVM can be local or remote.

Plus:

  • You can view logs as Jylog consoles generate them, instead of after the program executes.
  • A program can have multiple log configurations, in XML file format, which you can generate using the Jylog GUI. During an execution, you can select any configuration.


In a future release, Jylog's design will let you incorporate conditional logging -- that is, the log will generate at a point only if a specified variable has a certain value or if a specified expression is true. In addition, Jylog will support distributed logging; it will connect to more than one JVM and generate execution logs.

  • Print
  • Feedback

Resources