Java的Log是一个非常强大的写日志的工具包,程序员可以随时把一些想要记录的信息输出到本地文件,可以用于观察程序运行状况等,下面给出一个简单的小程序。
http://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/log4j/log4j.html
有log的相信说明文档
public static void main(String args[]) {
Logger logger = Logger.getLogger(ApacheLog.class);
SimpleLayout layout = new SimpleLayout();
FileAppender appender = null;
try {
appender = new FileAppender(layout, "myApacheLog.log", false);
} catch (Exception e) {
}
logger.addAppender(appender);
// Set the logger level to Level.INFO
logger.setLevel(Level.INFO);
// This request will be disabled since Level.DEBUG < Level.INFO.
logger.debug("This is debug.");
// These requests will be enabled.
logger.info("This is an info.");
logger.warn("This is a warning.");
logger.error("This is an error.");
logger.fatal("This is a fatal error.");
}
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import org.apache.log4j.SimpleLayout;
public class ApacheLog {
}