-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit Tomcat HTTP logs to stdout from Docker
Tomcat emits its own startup and shutdown logs by default, but also emits HTTP access logs to logs/localhost_access_log.YYYY-MM-DD.txt. This dynamically rewrites the conf/server.xml file to emit the HTTP logs to standard output instead. As mentioned in the update-tomcat-logging-config.sh comment, this configuration was inspired by: - https://stackoverflow.com/a/62598943 Got the Perl implementation hint from: - https://unix.stackexchange.com/a/26289 - https://unix.stackexchange.com/a/181215 Also updates the Dockerfile FROM from tomcat:10.1.16-jdk21-temurin-jammy to tomcat:10.1.16-jre21-temurin-jammy. The former was 211.56 MB compressed/454MB uncompressed, the latter 111.28 MB compressed/310MB uncompressed. - https://hub.docker.com/layers/library/tomcat/10.1.16-jdk21-temurin-jammy/images/sha256-857b168692495ee6ff0d6ee89b5b479555c74401bc3c219c88644b9181f03dd5?context=explore - https://hub.docker.com/layers/library/tomcat/10.1.16-jre21-temurin-jammy/images/sha256-7aaaf9a602c7160a644f1aa5cb1a42c584879769d9b78ef9e31f1055f392561a?context=explore
- Loading branch information
Showing
3 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Updates Tomcat config to log HTTP requests to standard output, per: | ||
# - https://stackoverflow.com/a/62598943 | ||
# | ||
# Takes the path to the Tomcat config as an argument, which it updates in place. | ||
# | ||
# See also: | ||
# - https://tomcat.apache.org/tomcat-10.1-doc/config/valve.html#Access_Logging | ||
|
||
ORIG_PAT=( | ||
'<Valve className="org.apache.catalina.valves.AccessLogValve"' | ||
'directory="logs"\n.*\n.* \/>' | ||
) | ||
NEW_VAL="<Valve className=\"org.apache.catalina.valves.AccessLogValve\" | ||
directory=\"\/dev\" prefix=\"stdout\" | ||
suffix=\"\" rotatable=\"false\" buffered=\"false\" | ||
pattern=\"%h %l %u %t "%r" %s %b\" \/>" | ||
|
||
# - https://unix.stackexchange.com/a/26289 | ||
# - https://unix.stackexchange.com/a/181215 | ||
exec perl -p0e "s/${ORIG_PAT[*]}/${NEW_VAL}/g" -i "$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
# syntax=docker/dockerfile:1.6.0 | ||
ARG TOMCAT_TAG=10.1.16-jdk21-temurin-jammy | ||
ARG TOMCAT_TAG=10.1.16-jre21-temurin-jammy | ||
|
||
FROM tomcat:${TOMCAT_TAG} | ||
|
||
COPY bin/update-tomcat-logging-config.sh /tmp/ | ||
|
||
RUN <<END_OF_LOGGING_CONFIG_UPDATE | ||
set -e | ||
/tmp/update-tomcat-logging-config.sh /usr/local/tomcat/conf/server.xml | ||
rm /tmp/update-tomcat-logging-config.sh | ||
END_OF_LOGGING_CONFIG_UPDATE | ||
|
||
COPY strcalc/build/libs/strcalc.war /usr/local/tomcat/webapps/ |