Nova
Nova

Reputation: 1270

View Tomcat log files in a browser

I need to somehow expose the Tomcat log files to a browser. I know that is not secure, but that's what's being requested.

I have considered making a hard link from the log location, such as tomcat/webapps/ROOT/html/catalina.out -> mydir/logs/catalina.out, but I don't think that's a good solution (even though it does work). Is there an established way of exposing Tomcat log files to a browser?

Upvotes: 18

Views: 21901

Answers (1)

David Fackler
David Fackler

Reputation: 385

This modification to distribution configurations will expose Tomcat logs over HTTP via the services of the Tomcat DefaultServlet. Confirmed with Tomcat distributions of 7.0.56, 8.0.24.

For purposes of this example, the canonical Tomcat distribution is given to be unpacked to /opt/tomcat.

In /opt/tomcat/conf/Catalina/localhost create the file logs.xml with this content:

<Context override="true" docBase="/opt/tomcat/logs" path="/logs" />

Restart Tomcat. Browse to a log file you know is there, e.g.

  • localhost:8080/logs/catalina.out

If you additionally desire to be able to browse the listing of logs, suggest this additional configuration change.

Edit /opt/tomcat/conf/web.xml. Where the listings parameter is configured, turn it on by setting its value to true:

...
<servlet>
...
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
...

Restart your tomcat for changes to take effect. Expect to see a list of log files as clickable links when conducting this test in a browser

  • localhost:8080/logs/

These settings are likely not desirable for some production environments due to either security or performance/resource usage concerns.

In some senses a rephrasing of this item: Simplest way to serve static data from outside the application server in a Java web application

Learn more (at the ragged edges of this question)

And the ever helpful docs

Upvotes: 24

Related Questions