log4j the log of the generated program.
First you need a configuration file:log4j.properties
Log4j.rootlogger = Debug, stdout, D, Elog4j.appender.stdout = org.apache.log4j.ConsoleAppenderlog4j.appender.stdout. Target = System.outlog4j.appender.stdout.layout = Org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern =%d{absolute}%5p%c{1}:%l-%m% NLOG4J.APPENDER.D = Org.apache.log4j.dailyrollingfileappenderlog4j.appender.d.file = logs/ Log.loglog4j.appender.d.append = Truelog4j.appender.d.threshold = Debuglog4j.appender.d.layout = Org.apache.log4j.patternlayoutlog4j.appender.d.layout.conversionpattern =%-d{yyyy-mm-dd HH:mm:ss} [%t:%r]-[%p]%m %NLOG4J.APPENDER.E = Org.apache.log4j.dailyrollingfileappenderlog4j.appender.e.file = logs/ Error.loglog4j.appender.e.append = Truelog4j.appender.e.threshold = Errorlog4j.appender.e.layout = Org.apache.log4j.patternlayoutlog4j.appender.e.layout.conversionpattern =%-d{yyyy-mm-dd HH:mm:ss} [%l:%c:%t:%r]-[ %p]%m%n
Instantiate logger in class <classname change to your class name >
private static Logger Logger = Logger.getlogger (Classname.class);
In the main function load configuration:
Propertyconfigurator.configure ("./config/log4j.properties");
Case:
Ogger.info ("log4j init success!");
Configuration and use of log4j