Wednesday, December 2, 2009

LogDigger Server 1.0



LogDigger is not only about real-time Java log monitoring any more! 

LogDigger Server 1.0 allows you to:
- Collect and save for later examination all events logged during the application usage session;
- Easily submit details-rich issue reports directly to your issue tracker (v1.0 integrates with JIRA, Bugzilla, Mantis and Redmine).

There’s free Community Edition of LogDigger Server. All accompanying tools and libraries are absolutely free.

More details and download at logdigger.com


Tuesday, November 10, 2009

Log4j versus JDK 1.4 Logging


This page describes some of the differences between the log4j API and the logging API included as part of Sun's JDK 1.4.

Why would you use log4j instead of the JDK logging API?
  • Log4j has been around since 1998 and many developers consider it to be a more mature framework.
  • Log4j 1.2.X is compatible with JDK 1.1 or later, Log4j 1.3 will be compatible with JDK 1.2 or later. The JDK 1.4 logging API requires JDK 1.4 or later. Consequently, if your applications needs to be deployed in a heterogeneous Java runtime environment, log4j can be considered as a safer bet.
  • Log4j has a much richer feature set. It has many more extensions that can be immediately used "out-of-the-box". Log4j includes many appenders (sinks or destinations for logging information) that JDK logging does not support out-of-the-box, e.g. SMTP, JDBC, and JMS.
  • As an open-source project, log4j continues to be developed and improved at a rapid pace. The improvements planned for log4j 1.3 will bring unparalleled functionality. The advancement of the technology in the logging related space is going to move faster in the log4j space than it is in the Sun/JDK space. Through bug fixes or talented committers joining the effort, more can happen here at Apache than can effectively be done at Sun where the focus and effort is on other things (like staying in business and not being crushed by M$, HP, IBM, etc).
  • Log4j includes log analysis GUIs: Chainsaw and  LogFactor5 .
  • Log4j commands a tremendous mind-share. Developers continue to make components available for the log4j framework, and in some instances only for the log4j framework.
  • Log4j performs well under heavy load. The next version of log4j should perform even better under extremely heavy load.
  • Being involved in an open source community means you can fix bugs, get your own patches applied in a timely fashion and have an influence over the future direction of the project.
  • In summary, if you are serious about logging, then log4j unfolds as the best option, probably by a large margin which keeps on widening.


Sunday, November 8, 2009

Overview of Log4j with example



Introduction to Log4j

Almost every large application includes its own logging or tracing API. In conformance with this rule, the E.U. SEMPER project decided to write its own tracing API. This was in early 1996. After countless enhancements, several incarnations and much work that API has evolved to become log4j, a popular logging package for Java. The latest log4j version, including full-source code, class files and documentation can be found at http://logging.apache.org/log4j/ . By the way, log4j has been ported to the C, C++, C#, Perl, Python, Ruby, and Eiffel languages.

Inserting log statements into code is a low-tech method for debugging it. It may also be the only way because debuggers are not always available or applicable. This is usually the case for multithreaded applications and distributed applications at large.

A Log4J example class

Here's a quick Log4j tutorial, with a lot of Log4j Java source code.
The following Java class is a very simple example that initializes, and then uses, the Log4J logging library for Java applications. As you can see the configuration is pretty simple.

package com.techpage.log4jdemo;
 
import org.apache.log4j.Category;
import org.apache.log4j.PropertyConfigurator;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.IOException;
 
/**
 * A simple Java Log4j example class.
 */
public class Log4JExample
{
  // our log4j category reference
  static final Category log = Category.getInstance(Log4JDemo.class);
  static final String LOG_PROPERTIES_FILE = "lib/Log4J.properties";
 
  public static void main(String[] args)
  {
    // call our constructor
    new Log4JExample();
 
    // Log4J is now loaded; try it
    log.info("leaving the main method of Log4JDemo");
  }
 
  public Log4JExample()
  {
    initializeLogger();
    log.info( "Log4JExample - leaving the constructor ..." );
  }
 
  private void initializeLogger()
  {
    Properties logProperties = new Properties();
 
    try
    {
      // load our log4j properties / configuration file
      logProperties.load(new FileInputStream(LOG_PROPERTIES_FILE));
      PropertyConfigurator.configure(logProperties);
      log.info("Logging initialized.");
    }
    catch(IOException e)
    {
      throw new RuntimeException("Unable to load logging property " + LOG_PROPERTIES_FILE);
    }
  }
}


After a few class level fields are created, the action in this Java Log4j example class begins with the main method, which first calls the class constructor. The constructor then calls theinitializeLogger method. This method actually does the work of loading the Log4J properties (configuration) file. It then calls the configure method of the PropertyConfiguratorclass.
Once this is done I call the info method of the Log4j logobject several times. Notice that I could have also called other methods like logger.warn(), log.debug(), log.error(), orlog.fatal(), but to keep it simple I'm just showinglog.info().

The Log4J properties file

Before I leave this quick tip I also need to show the Log4J configuration file that I'm using. My file is in the slightly older Log4j properties file format, because I actually prefer this format to the newer XML property file format. It is namedLog4J.properties, and for the purpose of this demonstration I'm keeping it in a sub-directory of my project named lib. Here are the contents:


#
# our log4j properties / configuration file
#
# STDOUT appender
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%d %p [%t] %C{1} - %m\n
 
# use the STDOUT appender. set the level to INFO.
log4j.category.com.techpage.log4jdemo.Log4JDemo=INFO, STDOUT