Approach 2 :  (log msgs into file) 

printed log messages  in Program level.
Here we are developing a java class for creating log messages file under program level.

Example:
package com.dustbin.test;
import java.io.IOException;
import org.apache.log4j.Appender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Layout;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.PropertyConfigurator;
public class Sample {
static Logger logger=Logger.getLogger(Sample.class);
public static void main(String[] args)throws IOException {
Layout layout=new PatternLayout();
Appender appender=new FileAppender(layout,"d:/vijay.txt");
logger.addAppender(appender);
logger.info("info message");
logger.warn("warn message");
logger.error("error message");
logger.fatal("fatal message");
logger.debug("debug msg");
}
}

output:

log messages are printed into file by creating file using java program

0 comments:

Post a Comment