我正在尝试创建一个servlet,它将从this示例
在浏览器上输出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);
但是这段代码不起作用,而浏览器窗口仍为空。我无法弄清楚它为什么不起作用?