创建文件”log4j.properties“,并写入:
# Configure logging for testing: optionally with log file输出的log文件为”MyTez.log“.
log4j.rootLogger=info, stdout, logfile
# debug>info>error
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
log4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=./Log/MyTez.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
代码中:
声明log文件:
private static final Logger LOG = LoggerFactory.getLogger(TezLogGenerator.class);TezLogGenerator为此自定的类;
写入log有:
LOG.info/LOG.error等。