Skip to content

Commit

Permalink
added backward compatibility
Browse files Browse the repository at this point in the history
- Backward compatibility through file checking has been added
- Pattern adapted to the old configuration file
  • Loading branch information
schmaddi committed Jul 30, 2021
1 parent 5f5244b commit 6a03dba
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
44 changes: 32 additions & 12 deletions configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,46 @@ 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() {
STDOUT_LOGGING=${STDOUT_LOGGING:-true}
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 ' <Console name="Console" target="SYSTEM_OUT">' /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 '/<Appenders>/ {r /log4j2.stdout.appenders.replace
d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml
sed -e '/<Root level="info" includeLocation="false">/ {r /log4j2.stdout.loggers.root.replace
d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml
sed -e '/<Logger name="com.jamfsoftware.analytics.file" level="info" additivity="false" includeLocation="false">/ {r /log4j2.stdout.loggers.analytics.replace
d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml
sed -e '/<AppenderRef ref="JAMFVPP"\/>/ {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 ' <Console name="Console" target="SYSTEM_OUT">' /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 '/<Appenders>/ {r /log4j2.stdout.appenders.replace
d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml
sed -e '/<Root level="info" includeLocation="false">/ {r /log4j2.stdout.loggers.root.replace
d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml
sed -e '/<Logger name="com.jamfsoftware.analytics.file" level="info" additivity="false" includeLocation="false">/ {r /log4j2.stdout.loggers.analytics.replace
d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml
sed -e '/<AppenderRef ref="JAMFVPP"\/>/ {r /log4j2.stdout.loggers.vpp.replace
d}' -i /usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.xml
fi
fi
fi
}
Expand Down
7 changes: 7 additions & 0 deletions log4j.stdout.replace
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion log4j2.stdout.appenders.replace
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Appenders>
<!--The appender for stdout logging-->
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"/>
</Console>

0 comments on commit 6a03dba

Please sign in to comment.