[logback-dev] [JIRA] Updates for LOGBACK-1546: logback-json-appender.xml: how to customize message pattern

QOS.CH (JIRA) noreply-jira at qos.ch
Thu Dec 31 11:23:00 CET 2020


logback / LOGBACK-1546 [Open]
logback-json-appender.xml: how to customize message pattern

==============================

Here's what changed in this issue in the last few minutes.
This issue has been created
This issue is now assigned to you.

View or comment on issue using this link
https://jira.qos.ch/browse/LOGBACK-1546

==============================
 Issue created
------------------------------

Nicola Spreafico created this issue on 31/Dec/20 11:08 AM
Summary:              logback-json-appender.xml: how to customize message pattern
Issue Type:           Improvement
Assignee:             Logback dev list
Created:              31/Dec/20 11:08 AM
Priority:             Major
Reporter:             Nicola Spreafico
Description:
  Hi,
  I have an App Engine application (java11) with Spring Boot.
  
   I configured the logback in order to write console_json logs on Cloud Logging.
  {code:java}
  <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>
  {code}
   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):
  
  
  [!https://user-images.githubusercontent.com/12278553/103377053-9bae0400-4ade-11eb-817c-2a366ceab760.png!|https://user-images.githubusercontent.com/12278553/103377053-9bae0400-4ade-11eb-817c-2a366ceab760.png]
  
  And this is an example of the log produced by my application with the given configuration:
  
  
  [!https://user-images.githubusercontent.com/12278553/103377156-df087280-4ade-11eb-8d3a-4ec3341a7ebf.png!|https://user-images.githubusercontent.com/12278553/103377156-df087280-4ade-11eb-8d3a-4ec3341a7ebf.png]
  
   
  
  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.
  
  I think that it's something related to {{JsonLayout}} and the possibility to customize the message in order to add the caller information.
  
  Thanks


==============================
 This message was sent by Atlassian Jira (v8.8.0#808000-sha1:e2c7e59)



More information about the logback-dev mailing list