0

I am trying to deploy a spring boot web app to Jboss EAP 7.1 server. When app runs in Tomcat (spring boot embedded tomcat server), by default it produces Json formatted logs as I have configured logback with slf4j.

But when I try to deploy the same in JBOSS, jboss is not writing any Json format logging. I checked in the web and found that logback is not supported out of the box in JBOSS EAP 7.1.

So I found an article to configure it in JBOSS. [https://blog.anotheria.net/devops/enable-logback-in-jboss/

Now I see that the default log manager is logback but output is still same as normal text?

Expected O/P:

{"timeStamp":"2020-04-27T21:38:28.411+05:30","message":"This is a warn message","logger":"com.example.demo.WelcomeController","thread":"http-nio-8080-exec-3","level":"WARN"}
{"timeStamp":"2020-04-27T21:38:28.415+05:30","message":"This is an error message","logger":"com.example.demo.WelcomeController","thread":"http-nio-8080-exec-3","level":"ERROR"}

Current O/P:

2020-04-27 21:12:17,787 INFO  [stdout] (default task-1) 21:12:17.787 [default task-1] DEBUG com.example.demo.WelcomeController - This is a debug message

2020-04-27 21:12:17,788 INFO  [stdout] (default task-1) 21:12:17.788 [default task-1] INFO com.example.demo.WelcomeController - This is an info message

2020-04-27 21:12:17,790 INFO  [stdout] (default task-1) 21:12:17.790 [default task-1] WARN com.example.demo.WelcomeController - This is a warn message

2020-04-27 21:12:17,793 INFO  [stdout] (default task-1) 21:12:17.791 [default task-1] ERROR com.example.demo.WelcomeController - This is an error message

Only changes between the article mentioned above and my configuration is the logback version -

<module xmlns="urn:jboss:module:1.5" name="ch.qos.logback">
    <resources>
        <resource-root path="logback-classic-1.2.3.jar"/>  
        <resource-root path="logback-core-1.2.3.jar"/>  
    </resources>

    <dependencies> 
        <module name="org.slf4j" />  
        <module name="javax.api" />  
        <module name="javax.mail.api" />  
    </dependencies>
</module>

So is there any additional change I have to do? How can I achieve the desired output.

Did not get any response in Jboss tag, so adding spring-boot tag, if anyone can help.

Amit Kumar
  • 85
  • 1
  • 2
  • 8
  • Are you trying to replace the log manager or do you just want JSON formatted log output? – James R. Perkins Apr 28 '20 at 16:05
  • @JamesR.Perkins I just want JSON formatted log as mentioned in expected output. So i changed to default logging for JBOSS from `org.jboss.logmanager` to ` ` – Amit Kumar Apr 28 '20 at 16:31
  • 1
    There's more than that required and it's definitely not supported. Since you're using EAP do you still want an unsupported solution? With JBoss EAP 7.2 there is a `json-formatter` in the logging subsystem. Replacing the log manager is not a simple task. – James R. Perkins Apr 28 '20 at 16:55
  • @JamesR.Perkins, So what do you recommend, shall we upgrade to JBoss EAP 7.2 and then use `json-formatter`? Or there is any other way we can do it in JBOSS EAP 7.1? – Amit Kumar Apr 30 '20 at 12:18
  • The only option for EAP 7.1 would be to write a custom JSON formatter which could be done. An example would be https://github.com/jboss-logging/jboss-logmanager/blob/2.1/src/main/java/org/jboss/logmanager/formatters/JsonFormatter.java. – James R. Perkins Apr 30 '20 at 17:09
  • @JamesR.Perkins, I am able to generate Json format in EAP 7.2 (not the way I wanted as custom fields I have to put in MDC, but manageable). I will try for a custom formatter in EAP7.1 – Amit Kumar May 04 '20 at 15:59
  • https://stackoverflow.com/questions/9518687/logback-and-jboss-7-dont-work-together/ – gavenkoa Mar 31 '22 at 14:09

0 Answers0