Skip to content

Commit 7f5af27

Browse files
Bill O'NeilBill O'Neil
authored andcommitted
Add logback json appender
1 parent 45c4a41 commit 7f5af27

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

gradle/dependencies.gradle

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ ext {
55
okhttp : '4.9.1', // HTTP Client
66
slf4j : '1.7.31', // Logging
77
logback : '1.2.5', // Logging
8-
undertow : '2.2.8.Final',// Webserver
8+
logbackJson : '0.1.5',
9+
undertow : '2.2.8.Final', // Webserver
910
metrics : '4.2.2', // Metrics
10-
guava : '30.1.1-jre', // Common / Helper libraries
11+
guava : '30.1.1-jre', // Common / Helper libraries
1112
typesafeConfig : '1.4.1', // Configuration
1213
handlebars : '4.2.0', // HTML templating
1314
htmlCompressor : '1.5.2', // HTML compression
1415
hikaricp : '4.0.3', // JDBC connection pool
1516
jool : '0.9.14', // Functional Utils
1617
hsqldb : '2.6.0', // In memory SQL db
17-
aws : '1.12.62', // AWS Java SDK
18+
aws : '1.12.62', // AWS Java SDK
1819
flyway : '5.1.4', // DB migrations
1920
connectorj : '8.0.25', // JDBC MYSQL driver
2021
jooq : '3.15.0', // jOOQ
@@ -25,7 +26,7 @@ ext {
2526
sitemapgen4j : '1.1.2', // Sitemap generator for SEO
2627
jbcrypt : '0.4', // BCrypt salted hashing library
2728
romeRss : '1.0', // RSS Library
28-
kotlin : '1.4.0', // Kotlin
29+
kotlin : '1.4.0', // Kotlin
2930
javax : '1.3.2',
3031
jbossLogging : '3.4.2.Final',
3132
jbossThreads : '3.4.0.Final',
@@ -55,6 +56,8 @@ ext {
5556
slf4jLog4j : "org.slf4j:log4j-over-slf4j:$versions.slf4j",
5657
logback : "ch.qos.logback:logback-classic:$versions.logback",
5758
logbackCore : "ch.qos.logback:logback-core:$versions.logback",
59+
logbackJson : "ch.qos.logback.contrib:logback-json-classic:$versions.logbackJson",
60+
logbackJackson : "ch.qos.logback.contrib:logback-jackson:$versions.logbackJson",
5861
guava : "com.google.guava:guava:$versions.guava",
5962
typesafeConfig : "com.typesafe:config:$versions.typesafeConfig",
6063
handlebars : "com.github.jknack:handlebars:$versions.handlebars",

k8s/chart/templates/stubbornjava.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ spec:
5252
env:
5353
- name: ENV
5454
value: "prod"
55+
- name: LOG_APPENDER
56+
value: "JSON"
5557
- name: github.clientId
5658
valueFrom:
5759
secretKeyRef:

stubbornjava-common/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ dependencies {
44
api project(':stubbornjava-undertow')
55
api libs.slf4j
66
api libs.logback
7+
api libs.logbackJson
8+
api libs.logbackJackson
79
api libs.jacksonCore
810
api libs.jacksonDatabind
911
api libs.jacksonDatabind

stubbornjava-webapp/src/main/resources/logback.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<configuration>
22

3+
<property name="LOG_APPENDER" value="${LOG_APPENDER:-STDOUT}" />
4+
5+
<!-- This appender is primarily used for local development -->
36
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
47
<!-- encoders are by default assigned the type
58
ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
@@ -8,8 +11,19 @@
811
</encoder>
912
</appender>
1013

14+
<!-- The JSON appender is meant to be machine friendly for log parsing -->
15+
<appender name="JSON" class="ch.qos.logback.core.ConsoleAppender">
16+
<layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
17+
<jsonFormatter
18+
class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
19+
<prettyPrint>true</prettyPrint>
20+
</jsonFormatter>
21+
<timestampFormat>yyyy-MM-dd' 'HH:mm:ss.SSS</timestampFormat>
22+
</layout>
23+
</appender>
24+
1125
<root level="INFO">
12-
<appender-ref ref="STDOUT" />
26+
<appender-ref ref="${LOG_APPENDER}" />
1327
</root>
1428

1529
<!--

0 commit comments

Comments
 (0)