Quarkus logging to json is not working in openshift okd version 3.11

905 views Asked by At

I have a challenge with loggings in Openshift with Quarkus as the JSON format I'm trying to get does work when testing locale, but when running it on Openshift I keep getting normal log lines. The problem with this is that log messages are all single lines in the Elasticsearch database and added MDC values are not included.

Main questions:

  • Is this default behavior on Openshift OKD, or might it be a problem with the base image?
  • Is there a way to adjust this behavior?
  • How else might I make sure that logs are processed in JSON style for my specific project in Openshift OKD?

Example data

locale, when run with: mvnw.cmd compile quarkus:dev the log is in json format: e.g:

Listening for transport dt_socket at address: 5005
Listening for transport dt_socket at address: 5005
{"timestamp":"2020-09-29T11:53:37.276+02:00","sequence":254,"loggerClassName":"org.jboss.logging.Logger","loggerName":"io.quarkus.deployment.QuarkusAugmentor","level":"WARN","message":"Using Java versions older than 11 to build Quarkus applications is deprecated and will be disallowed in a future release!","threadName":"main","threadId":1,"mdc":{},"ndc":"","hostName":"...","processName":"openshiftlogtest-dev.jar","processId":5740}
{"timestamp":"2020-09-29T11:53:40.658+02:00","sequence":1444,"loggerClassName":"org.jboss.logging.Logger","loggerName":"io.quarkus","level":"INFO","message":"openshiftlogtest 1.0.0-SNAPSHOT on JVM (powered by Quarkus 1.8.1.Final) started in 3.509s. Listening on: http://0.0.0.0:8080","threadName":"Quarkus Main Thread","threadId":69,"mdc":{},"ndc":"","hostName":"...","processName":"openshiftlogtest-dev.jar","processId":5740}
{"timestamp":"2020-09-29T11:53:40.659+02:00","sequence":1445,"loggerClassName":"org.jboss.logging.Logger","loggerName":"io.quarkus","level":"INFO","message":"Profile dev activated. Live Coding activated.","threadName":"Quarkus Main Thread","threadId":69,"mdc":{},"ndc":"","hostName":"...","processName":"openshiftlogtest-dev.jar","processId":5740}
{"timestamp":"2020-09-29T11:53:40.66+02:00","sequence":1446,"loggerClassName":"org.jboss.logging.Logger","loggerName":"io.quarkus","level":"INFO","message":"Installed features: [cdi, resteasy]","threadName":"Quarkus Main Thread","threadId":69,"mdc":{},"ndc":"","hostName":"...","processName":"openshiftlogtest-dev.jar","processId":5740}
{"timestamp":"2020-09-29T11:59:52.5+02:00","sequence":1447,"loggerClassName":"org.jboss.slf4j.JBossLoggerAdapter","loggerName":"com.onetrail.cis.healthcare.ExampleResource","level":"INFO","message":"Hello\r\nwho ami?\r\n","threadName":"executor-thread-1","threadId":73,"mdc":{"testKey":"testValue"},"ndc":"","hostName":"...","processName":"openshiftlogtest-dev.jar","processId":5740}

When deploying it to Openshift: The logging stays a plain log file where each line is seen as a separate log entry:

INFO: Installed features: [cdi, resteasy]
Sep 29, 2020 9:31:39 AM com.onetrail.cis.healthcare.ExampleResource hello
INFO: Hello
who ami?

Sep 29, 2020 9:31:42 AM com.onetrail.cis.healthcare.ExampleResource hello
INFO: Hello
who ami?

Sep 29, 2020 9:31:44 AM com.onetrail.cis.healthcare.ExampleResource hello
INFO: Hello
who ami?

Configuration

pom.xml:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>...</groupId>
    <artifactId>.../artifactId>
    <version>...</version>
    <properties>
        <compiler-plugin.version>3.8.1</compiler-plugin.version>
        <maven.compiler.parameters>true</maven.compiler.parameters>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <quarkus-plugin.version>1.8.1.Final</quarkus-plugin.version>
        <quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
        <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
        <quarkus.platform.version>1.8.1.Final</quarkus.platform.version>
        <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
        <ch.qos.logback.version>1.2.3</ch.qos.logback.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>${quarkus.platform.artifact-id}</artifactId>
                <version>${quarkus.platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-logging-json</artifactId>
        </dependency>    
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <version>${quarkus-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-code</goal>
                            <goal>generate-code-tests</goal>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${compiler-plugin.version}</version>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>native</id>
            <activation>
                <property>
                    <name>native</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${surefire-plugin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <systemPropertyVariables>
                                        <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                                        <maven.home>${maven.home}</maven.home>
                                    </systemPropertyVariables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <quarkus.package.type>native</quarkus.package.type>
            </properties>
        </profile>
    </profiles>
</project>

Versions

  • docker base image: fabric8/s2i-java latest
  • OpenShift Master: v3.11.0+d55192e-371
  • Kubernetes Master: v1.11.0+d4cacc0
  • OpenShift Web Console:v3.11.0+ea42280
  • Image vesrion labelss:
    • Java: Java version: 1.8.0_252, vendor: Oracle Corporation
    • Maven: 3.5.4
1

There are 1 answers

0
Frank Rakhorst On BEST ANSWER

On Openshift the loggerManager was of type java.util.logManager while on local system the loggerManager was of type org.jboss.logmanager.LogManager

By starting on Openshift the java process with the property: -Djava.util.logging.manager=org.jboss.logmanager.LogManager The log was written as JSON.