Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

Commit

Permalink
Move to logback
Browse files Browse the repository at this point in the history
  • Loading branch information
ketan committed Oct 6, 2017
1 parent 7659b1a commit 63e0ee9
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 21 deletions.
17 changes: 5 additions & 12 deletions Dockerfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,12 @@ RUN \
# unzip the zip file into /go-agent, after stripping the first path prefix
unzip /tmp/go-agent.zip -d / && \
mv go-agent-<%= gocd_version %> /go-agent && \
rm /tmp/go-agent.zip && \
# ensure that logs are printed to console output
<% %w(agent-bootstrapper-log4j.properties agent-launcher-log4j.properties agent-log4j.properties).each do |log_properties_file| -%>
sed -i -e 's/\(log4j.rootLogger.*\)/\1, stdout/g' /go-agent/config/<%= log_properties_file %> && \
sed -i -e 's/\(log4j.rootCategory.*\)/\1, stdout/g' /go-agent/config/<%= log_properties_file %> && \
echo "" >> /go-agent/config/<%= log_properties_file %> && \
echo "" >> /go-agent/config/<%= log_properties_file %> && \
echo "# Log to stdout" >> /go-agent/config/<%= log_properties_file %> && \
echo "log4j.appender.stdout=org.apache.log4j.ConsoleAppender" >> /go-agent/config/<%= log_properties_file %> && \
echo "log4j.appender.stdout.layout=org.apache.log4j.PatternLayout" >> /go-agent/config/<%= log_properties_file %> && \
echo "log4j.appender.stdout.layout.conversionPattern=%d{ISO8601} %5p [%t] %c{1}:%L - %m%n" >> /go-agent/config/<%= log_properties_file %> && \
rm /tmp/go-agent.zip

# ensure that logs are printed to console output
<% %w(agent-bootstrapper-logback-include.xml agent-launcher-logback-include.xml agent-logback-include.xml).each do |log_config_file| -%>
COPY <%= log_config_file %> /go-agent/config/<%= log_config_file %>
<% end -%>
true

ADD docker-entrypoint.sh /

Expand Down
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ create_user_and_group_cmd = [

cp("#{ROOT_DIR}/docker-entrypoint.sh", "#{dir_name}/docker-entrypoint.sh")
cp "#{ROOT_DIR}/LICENSE-2.0.txt", "#{dir_name}/LICENSE-2.0.txt"
Dir['*-logback-include.xml'].each do |f|
cp f, "#{dir_name}"
end
end

task :build_docker_image do
Expand Down
32 changes: 32 additions & 0 deletions agent-bootstrapper-logback-include.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017 ThoughtWorks, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<included>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
${gocd.agentBootstrapper.logback.defaultPattern:-%date{ISO8601} %-5level [%thread] %logger{0}:%line - %msg%n}
</pattern>
</encoder>
</appender>


<root>
<appender-ref ref="CONSOLE"/>
</root>

</included>
31 changes: 31 additions & 0 deletions agent-launcher-logback-include.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017 ThoughtWorks, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<included>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
${gocd.agentLauncher.logback.defaultPattern:-%date{ISO8601} %-5level [%thread] %logger{0}:%line - %msg%n}
</pattern>
</encoder>
</appender>

<root>
<appender-ref ref="CONSOLE"/>
</root>

</included>
32 changes: 32 additions & 0 deletions agent-logback-include.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017 ThoughtWorks, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<included>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
${gocd.agent.logback.defaultPattern:-%date{ISO8601} %-5level [%thread] %logger{0}:%line - %msg%n}
</pattern>
</encoder>
</appender>


<root>
<appender-ref ref="CONSOLE"/>
</root>

</included>
18 changes: 9 additions & 9 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ if [ "$1" = '/go-agent/agent.sh' ]; then
fi
done

if [ ! -e "${AGENT_WORK_DIR}/config/agent-bootstrapper-log4j.properties" ]; then
try cp -rfv "/go-agent/config/agent-bootstrapper-log4j.properties" "${AGENT_WORK_DIR}/config/agent-bootstrapper-log4j.properties"
try chown go:go "${VOLUME_DIR}/config/agent-bootstrapper-log4j.properties"
if [ ! -e "${AGENT_WORK_DIR}/config/agent-bootstrapper-logback-include.xml" ]; then
try cp -rfv "/go-agent/config/agent-bootstrapper-logback-include.xml" "${AGENT_WORK_DIR}/config/agent-bootstrapper-logback-include.xml"
try chown go:go "${VOLUME_DIR}/config/agent-bootstrapper-logback-include.xml"
fi

if [ ! -e "${AGENT_WORK_DIR}/config/agent-launcher-log4j.properties" ]; then
try cp -rfv "/go-agent/config/agent-launcher-log4j.properties" "${AGENT_WORK_DIR}/config/agent-launcher-log4j.properties"
try chown go:go "${VOLUME_DIR}/config/agent-launcher-log4j.properties"
if [ ! -e "${AGENT_WORK_DIR}/config/agent-launcher-logback-include.xml" ]; then
try cp -rfv "/go-agent/config/agent-launcher-logback-include.xml" "${AGENT_WORK_DIR}/config/agent-launcher-logback-include.xml"
try chown go:go "${VOLUME_DIR}/config/agent-launcher-logback-include.xml"
fi

if [ ! -e "${AGENT_WORK_DIR}/config/agent-log4j.properties" ]; then
try cp -rfv "/go-agent/config/agent-log4j.properties" "${AGENT_WORK_DIR}/config/agent-log4j.properties"
try chown go:go "${VOLUME_DIR}/config/agent-log4j.properties"
if [ ! -e "${AGENT_WORK_DIR}/config/agent-logback-include.xml" ]; then
try cp -rfv "/go-agent/config/agent-logback-include.xml" "${AGENT_WORK_DIR}/config/agent-logback-include.xml"
try chown go:go "${VOLUME_DIR}/config/agent-logback-include.xml"
fi

setup_autoregister_properties_file "${AGENT_WORK_DIR}/config/autoregister.properties"
Expand Down

0 comments on commit 63e0ee9

Please sign in to comment.