I'm trying to use Logback with Wildfire 9. For that, I added a jboss-deployment-structure.xml file in my WEB-INF folder with this content (I excluded also Hibernate to be sure to not pull jboss-logging):
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
<exclusions>
<module name="org.hibernate" />
</exclusions>
</deployment>
</jboss-deployment-structure>
It's working fine except I have blank lines between each log:
14:25:25,249 INFO [org.jboss.as.jpa] (MSC service thread 1-8) WFLYJPA0002: Read persistence.xml for portalPU
14:25:25,253 INFO [org.jboss.as.jpa] (MSC service thread 1-8) WFLYJPA0002: Read persistence.xml for emptyPU
14:25:25,631 INFO [stdout] (MSC service thread 1-1) 14:25:25,556 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
14:25:25,631 INFO [stdout] (MSC service thread 1-1) 14:25:25,557 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
and:
14:26:49,827 INFO [stdout] (default task-2) 2016-05-03 14:26:49 [default task-2] DEBUG f.s.q.p.web.filters.InstallFilter -Users found: 1
14:26:50,676 INFO [stdout] (default task-3) 2016-05-03 14:26:50 [default task-3] DEBUG f.s.q.p.web.filters.InstallFilter -Users found: 1
14:26:50,716 INFO [stdout] (default task-4) 2016-05-03 14:26:50 [default task-4] DEBUG f.s.q.p.web.filters.InstallFilter -Users found: 1
14:26:50,760 INFO [stdout] (default task-5) 2016-05-03 14:26:50 [default task-5] DEBUG f.s.q.p.web.filters.InstallFilter -Users found: 1
14:26:50,779 INFO [stdout] (default task-6) 2016-05-03 14:26:50 [default task-6] DEBUG f.s.q.p.web.filters.InstallFilter -Users found: 1
14:26:51,162 INFO [stdout] (default task-8) 2016-05-03 14:26:51 [default task-8] DEBUG f.s.q.p.web.filters.InstallFilter -Users found: 1
14:26:51,180 INFO [stdout] (default task-7) 2016-05-03 14:26:51 [default task-7] DEBUG f.s.q.p.web.filters.InstallFilter -Users found: 1
In my logback.xml, I'm using this pattern for the console:
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern><![CDATA[%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} -%msg%n]]></Pattern>
</layout>
</appender>
And in the logging.properties file of Wildfly, I have this:
formatter.COLOR-PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.COLOR-PATTERN.properties=pattern
formatter.COLOR-PATTERN.pattern=%K{level}%d{HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%e%n
I think the problem is comming from the %n for the ConsoleAppender and the PatternFormatter. If I'm trying to remove the %n for ConsoleAppender, it's like if I don't have flushes anymore: I can't see the logs. If I remove the %n for PatternFormatter, I don't have the blank lines but Wildfly's logs don't have linefeed anymore.
How to have something clean without blank lines ?
Since WildFly wraps both System.out
and System.err
in a logger this would result in 2 line separators being printed if you use the pattern on your ConsoleAppender
. You can either try removing the %n
formatting from your ConsoleAppender
and using the immediateFlush=true
option or you could create yet another console-handler
that would not print a line separator and assign it to stdout
.
For the later here are some CLI commands that would achieve that.
/subsystem=logging/pattern-formatter=stdout-pattern:add(pattern="%s")
/subsystem=logging/console-handler=stdout-console:add(autoflush=true, named-formatter=stdout-pattern, target=System.out)
/subsystem=logging/logger=stdout:add(handlers=[stdout-console], use-parent-handlers=false)
These commands add a pattern that just prints the incoming message (since it's formatted via the logback ConsoleAppender
this should work). Then creates a new console-handler
which uses the pattern. Finally adds a logger called stdout
and assigns the handler to it.