From 5f5244bd504c8f3585f4ca31b0a261bc29d09f9b Mon Sep 17 00:00:00 2001 From: schmaddi Date: Thu, 29 Jul 2021 15:12:43 +0200 Subject: [PATCH 1/2] Fixed logging to stdout Due to the change in the logging framework in jamf pro, the configuration file for Log4j has been changed. --- Dockerfile | 5 ++++- configuration.sh | 16 +++++++++++----- log4j.stdout.replace | 7 ------- log4j2.stdout.appenders.replace | 5 +++++ log4j2.stdout.loggers.analytics.replace | 2 ++ log4j2.stdout.loggers.root.replace | 2 ++ log4j2.stdout.loggers.vpp.replace | 2 ++ 7 files changed, 26 insertions(+), 13 deletions(-) delete mode 100644 log4j.stdout.replace create mode 100644 log4j2.stdout.appenders.replace create mode 100644 log4j2.stdout.loggers.analytics.replace create mode 100644 log4j2.stdout.loggers.root.replace create mode 100644 log4j2.stdout.loggers.vpp.replace diff --git a/Dockerfile b/Dockerfile index 7ce99b9..042928a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,10 @@ RUN apt-get update -qq && \ mkdir -p /usr/local/tomcat/webapps COPY startup.sh /startup.sh -COPY log4j.stdout.replace /log4j.stdout.replace +COPY log4j2.stdout.appenders.replace /log4j2.stdout.appenders.replace +COPY log4j2.stdout.loggers.analytics.replace /log4j2.stdout.loggers.analytics.replace +COPY log4j2.stdout.loggers.root.replace /log4j2.stdout.loggers.root.replace +COPY log4j2.stdout.loggers.vpp.replace /log4j2.stdout.loggers.vpp.replace COPY configuration.sh /configuration.sh CMD ["/startup.sh"] diff --git a/configuration.sh b/configuration.sh index f60b8c7..cbbe016 100755 --- a/configuration.sh +++ b/configuration.sh @@ -28,12 +28,18 @@ setup_stdout_logging() { if [[ $STDOUT_LOGGING == "true" ]]; then #Add stdout output for Jamf specific log files while maintaining logging to the files echo_time "STDOUT_LOGGING is true, add stdout logging for all logfiles" - if grep -Fxq "log4j.rootLogger=INFO,JAMF,stdout" /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties; then - echo_time "stdout logging appears to be present in log4j.properties file, skipping" + if grep -Fxq ' ' /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml; then + echo_time "stdout logging appears to be present in log4j2.xml file, skipping" else - echo_time "Add stdout logging to log4j.properties file" - sed -e '/log4j.rootLogger/ {r /log4j.stdout.replace - d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties + echo_time "Add stdout logging to log4j2.xml file" + sed -e '// {r /log4j2.stdout.appenders.replace + d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + sed -e '// {r /log4j2.stdout.loggers.root.replace + d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + sed -e '// {r /log4j2.stdout.loggers.analytics.replace + d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + sed -e '// {r /log4j2.stdout.loggers.vpp.replace + d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml fi fi } diff --git a/log4j.stdout.replace b/log4j.stdout.replace deleted file mode 100644 index bc632b7..0000000 --- a/log4j.stdout.replace +++ /dev/null @@ -1,7 +0,0 @@ -log4j.rootLogger=INFO,JAMF,stdout - -# Direct log messages to stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/log4j2.stdout.appenders.replace b/log4j2.stdout.appenders.replace new file mode 100644 index 0000000..1842f0b --- /dev/null +++ b/log4j2.stdout.appenders.replace @@ -0,0 +1,5 @@ + + + + + diff --git a/log4j2.stdout.loggers.analytics.replace b/log4j2.stdout.loggers.analytics.replace new file mode 100644 index 0000000..dc6710a --- /dev/null +++ b/log4j2.stdout.loggers.analytics.replace @@ -0,0 +1,2 @@ + + diff --git a/log4j2.stdout.loggers.root.replace b/log4j2.stdout.loggers.root.replace new file mode 100644 index 0000000..e821773 --- /dev/null +++ b/log4j2.stdout.loggers.root.replace @@ -0,0 +1,2 @@ + + diff --git a/log4j2.stdout.loggers.vpp.replace b/log4j2.stdout.loggers.vpp.replace new file mode 100644 index 0000000..a6b4055 --- /dev/null +++ b/log4j2.stdout.loggers.vpp.replace @@ -0,0 +1,2 @@ + + From 6a03dbaafabb2ac20a313bd3a92f7a6c79eff415 Mon Sep 17 00:00:00 2001 From: schmaddi Date: Fri, 30 Jul 2021 10:43:55 +0200 Subject: [PATCH 2/2] added backward compatibility - Backward compatibility through file checking has been added - Pattern adapted to the old configuration file --- Dockerfile | 3 ++- configuration.sh | 44 ++++++++++++++++++++++++--------- log4j.stdout.replace | 7 ++++++ log4j2.stdout.appenders.replace | 2 +- 4 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 log4j.stdout.replace diff --git a/Dockerfile b/Dockerfile index 042928a..5c50891 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,10 +10,11 @@ RUN apt-get update -qq && \ mkdir -p /usr/local/tomcat/webapps COPY startup.sh /startup.sh +COPY log4j.stdout.replace /log4j.stdout.replace COPY log4j2.stdout.appenders.replace /log4j2.stdout.appenders.replace COPY log4j2.stdout.loggers.analytics.replace /log4j2.stdout.loggers.analytics.replace COPY log4j2.stdout.loggers.root.replace /log4j2.stdout.loggers.root.replace -COPY log4j2.stdout.loggers.vpp.replace /log4j2.stdout.loggers.vpp.replace +COPY log4j2.stdout.loggers.vpp.replace /log4j2.stdout.loggers.vpp.replace COPY configuration.sh /configuration.sh CMD ["/startup.sh"] diff --git a/configuration.sh b/configuration.sh index cbbe016..72f1710 100755 --- a/configuration.sh +++ b/configuration.sh @@ -20,7 +20,13 @@ unpack_root_war() { setup_linux_logging_paths() { #Replace Mac logging paths with linux based paths echo_time "Set logging file paths to use linux file paths" - sed -i s#/Library/JSS/Logs#/usr/local/tomcat/logs# /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties + #Check whether log4j.properties (<= Jamf Pro 10.30.3) or log4j2.xml (>= Jamf Pro 10.31.0) exists + FILE=/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties + if test -f "$FILE"; then + sed -i s#/Library/JSS/Logs#/usr/local/tomcat/logs# /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties + else + sed -i s#/Library/JSS/Logs#/usr/local/tomcat/logs# /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + fi } setup_stdout_logging() { @@ -28,18 +34,32 @@ setup_stdout_logging() { if [[ $STDOUT_LOGGING == "true" ]]; then #Add stdout output for Jamf specific log files while maintaining logging to the files echo_time "STDOUT_LOGGING is true, add stdout logging for all logfiles" - if grep -Fxq ' ' /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml; then - echo_time "stdout logging appears to be present in log4j2.xml file, skipping" + #Check whether log4j.properties (<= Jamf Pro 10.30.3) or log4j2.xml (>= Jamf Pro 10.31.0) exists + FILE=/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties + if test -f "$FILE"; then + echo_time "Found log4j.properties, enable logging to stdout" + if grep -Fxq "log4j.rootLogger=INFO,JAMF,stdout" /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties; then + echo_time "stdout logging appears to be present in log4j.properties file, skipping" + else + echo_time "Add stdout logging to log4j.properties file" + sed -e '/log4j.rootLogger/ {r /log4j.stdout.replace + d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j.properties + fi else - echo_time "Add stdout logging to log4j2.xml file" - sed -e '// {r /log4j2.stdout.appenders.replace - d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml - sed -e '// {r /log4j2.stdout.loggers.root.replace - d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml - sed -e '// {r /log4j2.stdout.loggers.analytics.replace - d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml - sed -e '// {r /log4j2.stdout.loggers.vpp.replace - d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + echo_time "Found log4j2.xml, enable logging to stdout" + if grep -Fxq ' ' /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml; then + echo_time "stdout logging appears to be present in log4j2.xml file, skipping" + else + echo_time "Add stdout logging to log4j2.xml file" + sed -e '// {r /log4j2.stdout.appenders.replace + d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + sed -e '// {r /log4j2.stdout.loggers.root.replace + d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + sed -e '// {r /log4j2.stdout.loggers.analytics.replace + d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + sed -e '// {r /log4j2.stdout.loggers.vpp.replace + d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml + fi fi fi } diff --git a/log4j.stdout.replace b/log4j.stdout.replace new file mode 100644 index 0000000..bc632b7 --- /dev/null +++ b/log4j.stdout.replace @@ -0,0 +1,7 @@ +log4j.rootLogger=INFO,JAMF,stdout + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/log4j2.stdout.appenders.replace b/log4j2.stdout.appenders.replace index 1842f0b..98201bd 100644 --- a/log4j2.stdout.appenders.replace +++ b/log4j2.stdout.appenders.replace @@ -1,5 +1,5 @@ - +