Skip to content

Commit

Permalink
Added support for displaying Maven logs in JSON
Browse files Browse the repository at this point in the history
This solves GH issue apache#1783
  • Loading branch information
orpiske committed May 4, 2021
1 parent f24608d commit 5d5b5b8
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 3 deletions.
7 changes: 6 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ RUN mkdir -p /usr/share/maven \
&& echo "${SHA} /tmp/maven.tar.gz" | sha512sum -c - \
&& tar -xzC /usr/share/maven --strip-components=1 -f /tmp/maven.tar.gz \
&& rm -v /tmp/maven.tar.gz \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn \
&& rm /usr/share/maven/lib/maven-slf4j-provider*

ADD build/_maven_output /tmp/artifacts/m2
ADD build/_kamelets /kamelets
COPY build/_maven_overlay/ /usr/share/maven/lib/
ADD build/logback.xml /usr/share/maven/conf/

ENV MAVEN_OPTS="${MAVEN_OPTS} -Dlogback.configurationFile=/usr/share/maven/conf/logback.xml"

USER 0

Expand Down
62 changes: 62 additions & 0 deletions build/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!--
This configuration tries to output the Maven build log in a way that is as close as possible the native k8s
log output format.
-->
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<logLevel>
<fieldName>level</fieldName>
</logLevel>
<timestamp>
<fieldName>ts</fieldName>
<timeZone>UTC</timeZone>
</timestamp>
<loggerName>
<fieldName>logger</fieldName>
</loggerName>
<message>
<fieldName>msg</fieldName>
</message>
<callerData>
<classFieldName>class</classFieldName>
</callerData>
<threadName>
<fieldName>thread</fieldName>
</threadName>
<mdc/>
<arguments>
<includeNonStructuredArguments>false</includeNonStructuredArguments>
</arguments>
<logstashMarkers/>
<stackTrace>
<fieldName>stack</fieldName>
<throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
<maxLength>4096</maxLength>
<rootCauseFirst>false</rootCauseFirst>
</throwableConverter>
</stackTrace>
</providers>
</encoder>
</appender>

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

</configuration>
9 changes: 7 additions & 2 deletions script/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ clean:
rm -f kamel
rm -f *.test
rm -rf build/_maven_output
rm -rf build/_maven_overlay
rm -rf build/_output
rm -rf camel-k-client-*.tar.gz
rm -rf camel-k-examples-*.tar.gz
Expand All @@ -237,7 +238,11 @@ lint-fix:
check-licenses:
./script/check_licenses.sh

images: bundle-kamelets test
maven-overlay:
mkdir -p build/_maven_overlay
./script/maven_overlay.sh build/_maven_overlay

images: bundle-kamelets test maven-overlay
mkdir -p build/_maven_output
mkdir -p build/_output/bin
ifneq ($(shell uname -s 2>/dev/null || echo Unknown),Linux)
Expand All @@ -247,7 +252,7 @@ else
endif
docker build -t $(IMAGE_NAME):$(VERSION) -f build/Dockerfile .

images-dev: bundle-kamelets test package-artifacts
images-dev: bundle-kamelets test package-artifacts maven-overlay
mkdir -p build/_maven_output
mkdir -p build/_output/bin
ifneq ($(shell uname -s 2>/dev/null || echo Unknown),Linux)
Expand Down
23 changes: 23 additions & 0 deletions script/maven_overlay.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

mvn dependency:get -Dartifact=ch.qos.logback:logback-core:1.2.3 -Ddest=$1
mvn dependency:get -Dartifact=ch.qos.logback:logback-classic:1.2.3 -Ddest=$1
mvn dependency:get -Dartifact=net.logstash.logback:logstash-logback-encoder:4.11 -Ddest=$1
mvn dependency:get -Dartifact=com.fasterxml.jackson.core:jackson-annotations:2.9.10 -Ddest=$1
mvn dependency:get -Dartifact=com.fasterxml.jackson.core:jackson-core:2.9.10 -Ddest=$1
mvn dependency:get -Dartifact=com.fasterxml.jackson.core:jackson-databind:2.9.10.8 -Ddest=$1

0 comments on commit 5d5b5b8

Please sign in to comment.