Skip to content

Commit

Permalink
Merge pull request #11 from schmaddi/master
Browse files Browse the repository at this point in the history
Fixed logging to stdout
  • Loading branch information
battlecow authored Aug 2, 2021
2 parents 93590bb + 6a03dba commit 9f484d1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ RUN apt-get update -qq && \

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"]
Expand Down
38 changes: 32 additions & 6 deletions configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +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 "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"
#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 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 "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
5 changes: 5 additions & 0 deletions log4j2.stdout.appenders.replace
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Appenders>
<!--The appender for stdout logging-->
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"/>
</Console>
2 changes: 2 additions & 0 deletions log4j2.stdout.loggers.analytics.replace
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Logger name="com.jamfsoftware.analytics.file" level="info" additivity="false" includeLocation="false">
<AppenderRef ref="Console"/>
2 changes: 2 additions & 0 deletions log4j2.stdout.loggers.root.replace
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Root level="info" includeLocation="false">
<AppenderRef ref="Console"/>
2 changes: 2 additions & 0 deletions log4j2.stdout.loggers.vpp.replace
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<AppenderRef ref="JAMFVPP"/>
<AppenderRef ref="Console"/>

0 comments on commit 9f484d1

Please sign in to comment.