Simple Java application (with Logback) that drops logs with line breaks and a stack trace on startup. The goal is to test how OpenShift/Kubernetes ELK stack can handle multiline logs.
Two main approaches:
-
Use the logstash-logback-encoder to write structured JSON logs
-
Convert '\n' (LF) line breaks to '\r' (CR)
Uses net.logstash.logback.encoder.LogstashEncoder encoder to format logs as JSON objects. Run with logback-logstash Spring profile to try, see logback-logstash.xml:
mvn -Dspring.profiles.active=logback-logstash clean spring-boot:run
The log lines are wrapped in JSON format including all the line breaks for a log event. Fluentd parses the JSON object fields and forwards the log event to Elasticsearch with the correct metadata fields: timestamp, level, logger, message.
Uses Logback’s %replace() feature to convert all '\n' (line feed - \u000D) to '\r' (carriage return - \u000A) characters. The log event is handled as one line on the Docker level, but line breaks look good in Kibana UI. Run with the default Spring profile to use logging pattern defined in application.yaml:
mvn clean spring-boot:run
Run with the logback-pattern Spring profile to use logback-pattern.xml:
mvn -Dspring.profiles.active=logback-pattern clean spring-boot:run
Use fabric8 maven profile to deploy on OpenShift:
mvn -P fabric8 -DskipTests clean install
This is designed to run in OpenShift. See run.sh with the small perl script that converts back '\r' to line ending if you want to try on localhost.