Search code examples
loggingformatspring-cloudlogbackgoogle-cloud-run

Google Spring Cloud logback-json-appender hides information like thread or logging class


Situation:

Spring-Boot Application using Logback for logging. Deployed at google cloud run. Logback configuration includes CONSOLE_JSON, as described here, to have a preconfigured json appender for cloud run instances.

To see the logs for my application, i am using Cloud Run Logs.

Considering the default logs from spring, i have package/class message and other informations, written in the line.

Spring-Boot log sample: defualt log

Switching to a json format with the preconfigured appender, i miss a few informations for example shortened package with class name or thread name.

logback spring cloud log

I was hoping to use the existing console_json appender, to achieve this. Unfortunately i have to use google Logs Explorer and then look into a json entry called jsonPayload which is quite annoying from usability perspective Logs explorer

Desired Output:

  • somehow overwrite message format with logback to have the message contain thread and package/class infos, ideally not writing an own appender

Any help appreciated.

My Logback File looks like the following:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
  <include resource="com/google/cloud/spring/logging/logback-json-appender.xml"/>
  <include resource="org/springframework/boot/logging/logback/console-appender.xml" />

  <springProperty scope="context" name="SERVICE_NAME" source="logging.service"/>
  <springProperty scope="context" name="APP_NAME" source="logging.app"/>
  <springProperty scope="context" name="ENVIRONMENT" source="logging.environment"/>

  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight %cyan(%-5level) %logger{30} - %msg%n</pattern>
    </encoder>
</appender>
<springProfile name="npr">
    <root level="INFO">
        <appender-ref ref="CONSOLE_JSON"/>
    </root>
</springProfile>
<springProfile name="prd">
    <root level="INFO">
        <appender-ref ref="CONSOLE_JSON"/>
    </root>
</springProfile>
<springProfile name="local">
    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
    </root>
 </springProfile>
</configuration>

Solution

  • I see 2 options.

    1. Write my own Appender in case i really need this display pattern in a timely manner.
    2. as llompalles mentioned i give it a try with a GitHub Issue