Skip to content

Commit dad3d80

Browse files
Allows overriding of the default logging pattern
fixes gh-1863
1 parent 10ff663 commit dad3d80

File tree

6 files changed

+189
-64
lines changed

6 files changed

+189
-64
lines changed

README.adoc

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@ Consider the following example of a Logback configuration file (named https://gi
261261
<?xml version="1.0" encoding="UTF-8"?>
262262
<configuration>
263263
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
264-
264+
265265
<springProperty scope="context" name="springAppName" source="spring.application.name"/>
266266
<!-- Example for logging into the build folder of your project -->
267-
<property name="LOG_FILE" value="${BUILD_FOLDER:-build}/${springAppName}"/>
267+
<property name="LOG_FILE" value="${BUILD_FOLDER:-build}/${springAppName}"/>
268268
269269
<!-- You can override this to have a custom pattern -->
270270
<property name="CONSOLE_LOG_PATTERN"
@@ -282,7 +282,7 @@ Consider the following example of a Logback configuration file (named https://gi
282282
</encoder>
283283
</appender>
284284
285-
<!-- Appender to log to file -->
285+
<!-- Appender to log to file -->
286286
<appender name="flatfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
287287
<file>${LOG_FILE}</file>
288288
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
@@ -294,7 +294,7 @@ Consider the following example of a Logback configuration file (named https://gi
294294
<charset>utf8</charset>
295295
</encoder>
296296
</appender>
297-
297+
298298
<!-- Appender to log to file in a JSON format -->
299299
<appender name="logstash" class="ch.qos.logback.core.rolling.RollingFileAppender">
300300
<file>${LOG_FILE}.json</file>
@@ -310,6 +310,7 @@ Consider the following example of a Logback configuration file (named https://gi
310310
<pattern>
311311
<pattern>
312312
{
313+
"timestamp": "@timestamp",
313314
"severity": "%level",
314315
"service": "${springAppName:-}",
315316
"trace": "%X{traceId:-}",
@@ -325,7 +326,48 @@ Consider the following example of a Logback configuration file (named https://gi
325326
</providers>
326327
</encoder>
327328
</appender>
328-
329+
330+
<springProfile name="logzio">
331+
<!-- Use shutdownHook so that we can close gracefully and finish the log drain -->
332+
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
333+
<appender name="LogzioLogbackAppender" class="io.logz.logback.LogzioLogbackAppender">
334+
<token>${LOGZ_IO_API_TOKEN}</token>
335+
<logzioUrl>https://listener.logz.io:8071</logzioUrl>
336+
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
337+
<level>INFO</level>
338+
</filter>
339+
<debug>true</debug>
340+
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
341+
<providers>
342+
<timestamp>
343+
<timeZone>UTC</timeZone>
344+
</timestamp>
345+
<pattern>
346+
<pattern>
347+
{
348+
"timestamp": "@timestamp",
349+
"severity": "%level",
350+
"service": "${springAppName:-}",
351+
"trace": "%X{traceId:-}",
352+
"span": "%X{spanId:-}",
353+
"baggage": "%X{key:-}",
354+
"pid": "${PID:-}",
355+
"thread": "%thread",
356+
"class": "%logger{40}",
357+
"rest": "%message"
358+
}
359+
</pattern>
360+
</pattern>
361+
</providers>
362+
</encoder>
363+
</appender>
364+
365+
<root level="info">
366+
<!-- IMPORTANT: make sure to include this line, otherwise the appender won't be used -->
367+
<appender-ref ref="LogzioLogbackAppender"/>
368+
</root>
369+
</springProfile>
370+
329371
<root level="INFO">
330372
<appender-ref ref="console"/>
331373
<!-- uncomment this to have also JSON logs -->
@@ -714,7 +756,7 @@ If you do not use SLF4J, this pattern is NOT automatically applied.
714756

715757
== Building
716758

717-
:jdkversion: 1.7
759+
:jdkversion: 1.8
718760

719761
=== Basic Compile and Test
720762

0 commit comments

Comments
 (0)