Sunday, June 23, 2013

Initializing Log4j

Document  Version 1.0

package tryl4j;

import org.apache.log4j.Logger;

 * @author swang
public class TryLog4jInit {
private static final Logger logger = Logger.getLogger("MyLogger");
public static void main(String[] ages) {"Did you add  a  JVM param for initializing log4j?");

}  file

# Root logger option
log4j.rootLogger=INFO, stdout

# Direct log messages to stdout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

Run the above class with:


And you will see the warning is not showing up and more, and you  see the logged info in console:

2013-06-23 12:13:17 INFO  MyLogger:16 - Did you add  a  JVM param for  initializing log4j?

So the JVM parameter works!

No comments:

Post a Comment