Steps
for compile and run log4j program :
To compile and run applications, we need to set log4j-1.2.17.jar in classpath.
To compile and run application, we
need to set log4j-1.2.17.jar file.
step1: set the classpath
->set
CLASSPATH=log4j-1.2.17.jar;.;
step2: develop a java application
with log messages.
package
com.dustbin.test;
import org.apache.log4j.Logger;
public class
Sample {
static Logger logger=Logger.getLogger(Sample.class);
public static void
main(String[] args) {
BasicConfigurator.configure();
logger.info("info
message");
logger.warn("warn
message");
logger.error("error
message");
logger.fatal("fatal
message");
logger.debug("debug
msg");
}
}
step3: print a log messages on console
Output:
0 [main] INFO
com.dustbin.test.Sample - info message
0 [main] WARN
com.dustbin.test.Sample - warn message
0 [main] ERROR
com.dustbin.test.Sample - error message
0 [main] FATAL
com.dustbin.test.Sample - fatal message
0 [main] DEBUG com.dustbin.test.Sample - debug msg
0 comments:
Post a Comment