有没有办法在浏览器中实时查看我的web-apps tomcat日志?

我正在使用log4j来记录我的数据。 我希望能够在浏览器中与我的网络应用程序一起实时查看日志文件。 像Chainsaw这样的独立工具相当不错,但它们不能满足在浏览器中实时查看日志的目的。

任何人都可以帮我吗?

一个简单的例子是:

Servlet(根据需要更改日志文件的路径):

@WebServlet(name = "Log", urlPatterns = { "/log" }) public class LogServlet extends HttpServlet { private static final long serialVersionUID = 7503953988166684851L; public LogServlet() { super(); } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Path path = FileSystems.getDefault() .getPath("/path/to/tomcat/logs", "catalina.out"); StringBuilder logContent = new StringBuilder(); logContent.append("
"); try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8);) { String line = null; while ((line = reader.readLine()) != null) { logContent.append(line).append("
"); } } catch (IOException x) { // Take care of that } logContent.append("

"); resp.getWriter().print(logContent.toString()); } @Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); } }

HTML页面:

     Log viewer       

你可以使用psi-probe 。 它具有内置function,可实时访问日志,更改日志级别,下载等…