How to Log with log4j

1) Create the Log4jSample.java file:

import org.apache.log4j.Logger;

public final class Log4jSample {

  public static void main(final String[] args) {
    final Logger logger = Logger.getLogger(Log4jSample.class);

    logger.info("Hello World!");
  }

}

2) Create the log4j.properties file:

log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout

log4j.logger.Log4jSample=INFO, A1

3) Compile the Log4jSample.java file.

4) Launch the Log4jSample class.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s