0

I'm using Kinesis Client Library and it uses org.apache.commons.logging. Currently it prints all things on terminal. I want to let logs be written in a file instead.

I found this question Write log file using org.apache.commons.logging and tried to follow the steps. But I didn't see my log files in my specified path.

Here's what I've done:

First, I added two config files commons-logging.properties and log4j.properties in consumer/src folder. My TestLog.java file is in consumer/src/java.

In commons-logging.properties file:

org.apache.commons.logging.Log = org.apache.commons.logging.impl.Log4JLogger

In log4j.properties file:

handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler
.level=SEVERE
sample.logging.level=FINE
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.FileHandler.level=ALL
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.pattern=/Users/XXX/src/MyKinesis/firstlog

And here's my TestLog.java file

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

public class TestLog {

    private static Log log = LogFactory.getLog(TestLog.class);
    public static void main(String[] args) {
        log.info("Testing Info Message.");
        if (log.isDebugEnabled()) {
            System.out.println("HERE");
            log.debug("Testing Debug Message.");
        }
    }
}

And I executed this by

mvn exec:java -Dexec.mainClass="TestLog" -Djava.util.logging.config.file=~/src/MyKinesis/stockStream/src/log4j.properties

( ~/src/MyKinesis/stockStream/src/log4j.properties is the path where I stored the log4j.properties file)

But I didn't find the the log file at /Users/XXX/src/MyKinesis/firstlog. And also there's no output in the console. Why is that?

Any suggestions will be appreciated!!

Patrick
  • 555
  • 1
  • 6
  • 25

0 Answers0