如何从部署在其上的Java Web应用程序访问tomcat日志文件? 这可能吗?
答案 0 :(得分:0)
好的,有可能。我使用了类似的东西:
public static String readLogFile () {
StringBuilder sb = new StringBuilder();
try(BufferedReader br = new BufferedReader(new FileReader("/var/log/tomcat8/catalina.out"))) {
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
} catch (IOException e) {
// exception handling
}
return sb.toString();
}