我使用了一个初始化记录器和参数的函数。虽然我在控制台中调用了这个函数 LogMsg 和换行符,但它在文本文件中只给出了一行。为什么呢?
String logmsg="Line1\n"+"Line2\n";
public static void LogMsg(Logger logger,String pathname,Level level,String logmsg){
//logger=Logger.getLogger("LogMsg");
FileHandler fh=null;
try {
fh = new FileHandler(pathname,300000,1,true);
fh.setFormatter(new SimpleFormatter());
LogRecord record1 = new LogRecord(level, logmsg);
logger.addHandler(fh);
logger.log(record1);
fh.close();
} catch (SecurityException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println("Failed to log message due to lack of permissions.");
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println("Failed to log message");
}
}