1. download log4j.jar
2. import it to Elicpse
3. it can output various log to console or files.
Examples:
if you file name is testlog4j.java, then...
public class testlog4j {
//using log4j;
private static Logger logger = Logger.getLogger(testlog4j.class.getName());
public static void main(String[] args) throws Exception, IOException {
long limit = 1000000;
//XMLLayout layout1 = new XMLLayout();//
SimpleLayout layout = new SimpleLayout();
FileAppender appender = null;
try {
appender = new FileAppender(layout,"D:\\output.log", false);
} catch(Exception e) {}
logger.addAppender(appender);
logger.setLevel((Level) Level.ALL);
logger.info("Here is some INFO");
}
}
If you want to append log, set
appender = new FileAppender(layout,"D:\\output.log", true);