Java – wildfly and logback of blank lines
I'm trying to use wildfire 9's logback To do this, I added a JBoss - Deployment - structure. JSP in my web - inf folder XML file and this content (I also excluded hibernate to ensure that JBoss logging is not pulled):
<?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 works normally, except that I have a blank line 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,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
On my logback XML, I use 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>
In wildfly's logging In the properties file, 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 comes from the% n of consoleappender and patternformatter. If I'm trying to delete the% n of consoleappender, it's like I didn't flush: I can't see the log If I delete% n of patternformatter, I have no blank lines, but wildfly's log no longer has line breaks
How to clean things without empty lines?
Solution
Because wildfly will system Out and system Err is wrapped in the recorder, so if this mode is used on console appender, it will cause 2 line separators to be printed You can try to remove the% n format from consoleappender and use the immediateflush = true option, or you can create another console handler that does not print line separators and assigns them to stdout
For the latter, there are some cli commands to do this
/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 of printing only incoming messages (because it is formatted through logback console appender, which should work) Then create a new console handler that uses this pattern Finally, add a logger named stdout and assign a handler to it