How to print logs in json format with meta-data field ?

104 views
Skip to first unread message

nehajo...@gmail.com

unread,
Mar 25, 2021, 6:48:27 AM3/25/21
to jBPM Usage

I am using jbpm 7.37 standard edition, with WildFly Full 14.0.1.Final (WildFly Core 6.0.2.Final). I am using logger class(org.slf4j.LoggerFactory,org.slf4j.Logger) to print the logs. I have enabled custom REST endpoints.I am using Jersey REST api. I am making custom jar fil where I have written custom code (custom REST APIs) and deploying this jar file inside kie-server.war file. I want to print logs in json format for my custom class. Like below :

{"timestamp":"2021-03-04T05:27:07.063Z", "service":"demo", "level":"error/info", "message":"Errormessage/Info message", "metadata":{"requestId":"somerequestid","sessionId":"somesif"} }

However i am able to print logs in json format with the below command :

sudo bash jboss-cli.sh -c "/subsystem=logging/json-formatter=json:com.demo.add(exception-output-type=formatted, pretty-print=true, meta-data={service=demo})"

But this gives me output like below :

{"timestamp":"2021-03-04T05:27:07.063Z", "service":"demo", "level":"error/info", "message":"Errormessage/Info message", }

Not able to print the "metadata":{"requestId":"somerequestid","sessionId":"somesrequestid"}

The fields requestId and sessionId are having runtime values which i have to get from the http request. From @HeaderParam("requestId"),@HeaderParam("sessionId") and needs to append with each and every response.

When i append this values in my response it shows inside the "message" field as follow.

{"timestamp":"2021-03-04T05:27:07.063Z", "service":"demo", "level":"error/info", "message":"data{"requestId":"somerequestId","sessionId":"somesessionId"}", }

How do i print the values for requestId and sessionId for each and every request as "metadata":{"requestId":"somerequestid","sessionId":"somesid"} ?

Reply all
Reply to author
Forward
0 new messages