How to Log with Apache Commons Logging and log4j

1) Create the file:

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public final class CommonsSample {

  public static void main(final String[] args) {
    final LogFactory factory = LogFactory.getFactory();

    final Log log = factory.getInstance(CommonsSample.class);"Hello World!");


2) Create the file:

org.apache.commons.logging.impl.Log4JLogger # default is org.apache.commons.logging.impl.SimpleLog

3) Create the file:


log4j.logger.CommonsSample=INFO, A1

4) Compile the file.

5) Launch the CommonsSample class.


Leave a Reply

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

You are commenting using your 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