import java.io.IOException;
import java.util.UUID;
import java.util.logging.*;
public class LogDemo {
public static void main(String[] args) throws IOException {
Logger global = Logger.getGlobal();
FileHandler fileHandler = new FileHandler("./tmp.log", true);
fileHandler.setFormatter(new CustomFormatter());
fileHandler.setEncoding("UTF-8");
global.addHandler(fileHandler);
LogRecord logRecord = new LogRecord(Level.INFO, UUID.randomUUID().toString() + "\n");
global.log(logRecord);
}
}
class CustomFormatter extends Formatter {
@Override
public String format(LogRecord record) {
return record.getMessage();
}
}
标签:原生,java,log,fileHandler,global,import,public
From: https://www.cnblogs.com/renguanyu/p/18211518