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.
Switching to a json format with the preconfigured appender, i miss a few informations for example shortened package with class name or thread name.
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
Desired Output:
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>
I see 2 options.