我正在尝试创建一个 servlet,它将从此示例在浏览器上输出Tomcat日志
File logFile = new File(System.getProperty("catalina.base"), "logs/catalina.log");
String contents = FileUtils.readFileToString(logFile);
PrintWriter out = new PrintWriter(resp.getOutputStream());
out.println(contents);
这工作正常,但我正在尝试更改代码以获取catalina.2012-11-29.log的输出。修改后的代码如下
Log.log(Level.OFF, "Inside doGet of LogServlet");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//get current date time with Date()
Date date = new Date();
Log.log(Level.INFO, "Date = {0}", dateFormat.format(date));
String fileName = "logs/catalina." + dateFormat.format(date) + ".log";
Log.log(Level.INFO, "fileName = {0}", fileName);
Log.log(Level.INFO, "System.getProperty(catalina.base) = {0}", System.getProperty("catalina.base"));
File logFile = new File(System.getProperty("catalina.base"), fileName);
String contents = FileUtils.readFileToString(logFile);
PrintWriter out = new PrintWriter(response.getOutputStream());
out.println(contents);
但是这段代码不起作用,浏览器窗口仍然是空的。我无法弄清楚为什么它不起作用?