9

Tomcat9 deployed on Ubuntu 18.04. This issue ONLY applies to Tomcat version 9. There is a catalina.date.log file present in the logs folder but it does NOT show any console printouts from our web applications.

I've set the ConsoleHandler level to ALL in logging.properties, still no logs.

Any pointers, ideas? Thanks!

Lucian
  • 93
  • 1
  • 1
  • 4
  • On Debian 10 **stdout** and **stderr** are captured by `systemd-journald`, so try `journalctl -u tomcat9.service`. – Piotr P. Karwasz Nov 26 '19 at 22:16
  • Before installing tomcat9, i was using tomcat8 which was capturing the stdout and stderr and was saving the logs in catalina.out. I haven't changed OSs, – Lucian Nov 27 '19 at 15:01
  • How can i configure journalctl to only save the logs from tomcat9 to a file somewhere? – Lucian Nov 27 '19 at 15:02
  • I was talking about Debian 10, since I don't have Ubuntu 18.04, but the packages are almost identical. – Piotr P. Karwasz Nov 27 '19 at 19:30

2 Answers2

9

The tomcat9 package on Ubuntu 18.04 (and Debian 10) use a systemd .service file. By default they redirect Tomcat's stdout and stderr to syslog with a program name tomcat9. In Debian 10 RSyslog is configured to write those to /var/log/tomcat9/catalina.out, but that might not be true in your case.

So you have at least two solutions:

  1. Read the output from systemd-journald:

    journalctl -u tomcat9.service
    

    You probably want to make journald storage persistent (the solution for CentOS also applies to Ubuntu).

  2. Modify the .service file to redirect output to /var/log/tomcat9/catalina.out

    systemctl edit --full tomcat9.service
    

    and follow the instructions on StackOverflow.

Remark that “logging” through System.out.println and similar is bad practice, since you cannot control what is logged and how. You can use the swallowOutput attribute on the context if you want to send those statements to java.util.logging. All messages logged through ServletContext#log() and java.util.logging end up in either catalina.<date>.log or localhost.<date>.log.

Piotr P. Karwasz
  • 5,292
  • 2
  • 9
  • 20
0

On my configuration (VM, Ubuntu 18.04 server, tomcat9) I have found tomcat stdout messages in the /var/log/syslog file:

root@deploytest:/var/log# less syslog

Dec  4 07:17:43 deploytest systemd[1]: Starting Apache Tomcat 9 Web Application Server...
Dec  4 07:17:43 deploytest systemd[1]: Started Apache Tomcat 9 Web Application Server.
Dec  4 07:17:44 deploytest tomcat9[3235]: Server version name:   Apache Tomcat/9.0.16 (Ubuntu)
Dec  4 07:17:44 deploytest tomcat9[3235]: Server built:          Sep 11 2019 19:47:51 UTC
Dec  4 07:17:44 deploytest tomcat9[3235]: Server version number: 9.0.16.0
Dec  4 07:17:44 deploytest tomcat9[3235]: OS Name:               Linux
Dec  4 07:17:44 deploytest tomcat9[3235]: OS Version:            4.15.0-72-generic
Dec  4 07:17:44 deploytest tomcat9[3235]: Architecture:          amd64
Dec  4 07:17:44 deploytest tomcat9[3235]: Java Home:             /usr/lib/jvm/java-8-openjdk-amd64/jre
Dec  4 07:17:44 deploytest tomcat9[3235]: JVM Version:           1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10
Dec  4 07:17:44 deploytest tomcat9[3235]: JVM Vendor:            Private Build
Dec  4 07:17:44 deploytest tomcat9[3235]: CATALINA_BASE:         /var/lib/tomcat9
Dec  4 07:17:44 deploytest tomcat9[3235]: CATALINA_HOME:         /usr/share/tomcat9
...
Dec  4 07:18:01 deploytest tomcat9[3235]: Starting ProtocolHandler ["http-nio-8080"]
Dec  4 07:18:01 deploytest tomcat9[3235]: Server startup in [16,667] milliseconds
alexb
  • 101