Logback + Wildfly 8 - incorrect pattern

2019-07-22 04:35发布

问题:

I have a problem with logback + wildfly 8 configuration. I'm using simple ConsoleAppender:

appender("STDOUT", ConsoleAppender) {
    encoder(PatternLayoutEncoder) {
        pattern = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{70} - %msg%n"
    }
}
logger("com.package.app", INFO)
root(DEBUG, ["STDOUT"])

The problem is that Wildfly appends to logback messages also server's log pattern. It looks like:

11:31:49,954 INFO  [stdout] (default task-1) 11:31:49.951 [default task-1] INFO  com.package.app.controller.FrontController - message...

As You can see, there is a server logs pattern first and then the logback message

How to solve this problem?

回答1:

WildFly captures System.out and System.err and redirects them to a logger. You could configure a logger in WildFly with the name stdout, set the use-parent-handlers attribute to false and set the level to NONE. This should disable System.out from printing which means it will also not appear in the server.log.

That said, I don't see a reason to use logback for a ConsoleAppender since the server already provides one.