You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

JSON Approach

This has not been successfully tested on any other repo, but the CPS team implemented console JSON logging by adding the following to the XML files:

Add this where the appenders are for STDOUT and delete the old STDOUT appender (if there is one):

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<providers>
<pattern>
<omitEmptyFields>true</omitEmptyFields>
<pattern>
(        
"logTimeStamp": "$(currentTimeStamp",
"logTypeName": "",
"logLevel": "%level",
"traceId": "%X(traceId",
"statusCode": "",
"principalId": "$(username",
"serviceName": "$(springAppName",
"message": "%message",
"spanId": "%X(spanId",
"processId": "$(PID",
"threadName": "%thread",
"class": "%logger(40)",
"exception": "%WEx"        
)
</pattern>
</pattern>
</providers>
</encoder>
</appender>


Depending on how the logging files are setup, this could be added in the main XML or a separate file that has the property elements in it:

<property scope="context" name="springAppName" value="spring.application.name"/>
<property scope="context" name="username" value="security.auth.username"/>


String Output Approach

If the goal is to output strings to the console instead of JSON, these suggestions and resources might be helpful:

https://logback.qos.ch/manual/layouts.html

This documentation under pattern layouts shows all the fields that are available for outputting in a string format out of the box with logback core. We can also take advantage of the idea of adding <property> elements and referencing them in the log pattern as above.


General Notes

These notes are going to be here for extra help navigating the building and testing process to see if your logging changes are working:

  1. You may have to build the project from a subdirectory rather than the base project directory. This CI Management repo will help clarify where each of the projects are building from to better identify the subdirectory you should build from: https://github.com/onap/ci-management/tree/master/jjb/dcaegen2



  • No labels