Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

logback-json-appender.xml: how to customize message pattern #2619

Closed
NicolaSpreafico opened this issue Dec 30, 2020 · 6 comments
Closed

logback-json-appender.xml: how to customize message pattern #2619

NicolaSpreafico opened this issue Dec 30, 2020 · 6 comments
Labels
awaiting waiting for something external logging question

Comments

@NicolaSpreafico
Copy link

NicolaSpreafico commented Dec 30, 2020

Hi,
I have an App Engine application (java11) with Spring Boot.

<spring.boot.version>2.3.4.RELEASE</spring.boot.version>

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Hoxton.SR8</version>
            <type>pom</type>
            <scope>import</scope>
 </dependency>

I configured the logback in order to write console_json logs on Cloud Logging.

<configuration>
   <include resource="org/springframework/boot/logging/logback/defaults.xml" />
   <include resource="org/springframework/boot/logging/logback/console-appender.xml" />

   <springProfile name="development | stage | production">
      <include resource="org/springframework/cloud/gcp/logging/logback-json-appender.xml" />
      <root level="INFO">
         <appender-ref ref="CONSOLE_JSON" />
      </root>
   </springProfile>
   <springProfile name="localhost">
      <root level="INFO">
         <appender-ref ref="CONSOLE" />
      </root>
   </springProfile>
</configuration>

I'm trying to understand how (and if possible...) to configure the message pattern, I'd like to add the class and the line number which generated that specific log.

This is an example of a Java8 App Engine standard application (the first generation of App Engine where the log were directly integrated by the infrastructure):
image

And this is an example of the log produced by my application with the given configuration:
image

The log creation itself it's working as expected, but I'm not getting the class/line number. Of course I don't expect to obtain the same behaviour where the class reference is clickable, which integrates the sources and all of that.
In my case I'm simply trying to add those 2 pieces of information (as simple text) aside with the actual log message.

Also, if you notice from the first screenshot, in addition to class simple name and line number at the end, there is also at the beginning the fully qualified name of the class and the method name.

Is it something that is achievable at all? I tried playing with the <pattern> node of the xml but no luck, maybe I need to create a customLayout class or something, can you help me?

That data would be very helpful to me as I can directly open the sources pointing to the specific line which generated the log and start from there for debugging.

Thanks

@meltsufin
Copy link
Contributor

I don't think Logback JsonLayout supports caller location information. It might be worth asking the question in the Logback community.

@NicolaSpreafico
Copy link
Author

Thank you for the suggestion, I created an issue in logback community

@meltsufin
Copy link
Contributor

Thanks! Can you please provide a link to the issue here?

@NicolaSpreafico
Copy link
Author

@dzou dzou added the awaiting waiting for something external label Jan 21, 2021
@ttomsu
Copy link

ttomsu commented Feb 18, 2021

@NicolaSpreafico if you hear back from the Logback community that it is possible, please let us know. In the meantime, I'm going to close this issue as there's not much more we can do on this end.

@ttomsu ttomsu closed this as completed Feb 18, 2021
@NicolaSpreafico
Copy link
Author

Hi, no reply so far, at this point I don't know if I'll ever get one

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting waiting for something external logging question
Development

No branches or pull requests

4 participants