登录时,Jboss上的登录会重复前缀和换行 [英] Logback on Jboss duplicates prefixes and new lines when logging

查看:88
本文介绍了登录时,Jboss上的登录会重复前缀和换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Java Web项目.我使用Wildfly10.我想将其与logback一起使用.我做了一些配置:

I'm working on java web project. I use Wildfly 10. I want to use it with logback. I did some configuration:

pom.xml

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.24</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.2.1</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>1.2.1</version>
</dependency>

logback.xml

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender" >
        <encoder>
            <pattern>[%date] [%thread] [%-5level] [%logger{36}] - %msg%n </pattern>
        </encoder>
    </appender>

    <logger name="com.pr" level="debug" additivity="false">
        <appender-ref ref="STDOUT" />
    </logger>

  <root level="debug">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

jboss-deployment-structure.xml

jboss-deployment-structure.xml

<jboss-deployment-structure>
    <deployment>
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
</deployment>
</jboss-deployment-structure>

问题是我期望输出类似:

The problem is that I was expecting ouput like:

[2017-02-26 12:32:23,671] [ServerService线程池-179] [调试] [o.springframework.jndi.JndiTemplate]-查找JNDI

[2017-02-26 12:32:23,671] [ServerService Thread Pool -- 179] [DEBUG] [o.springframework.jndi.JndiTemplate] - Looking up JNDI

但是我得到了:

12:32:23,671信息[stdout](ServerService线程池-179)[2017-02-26 12:32:23,671] [ServerService线程池-179] [DEBUG] [o.springframework.jndi. JndiTemplate]-查找JNDI

12:32:23,671 INFO [stdout] (ServerService Thread Pool -- 179) [2017-02-26 12:32:23,671] [ServerService Thread Pool -- 179] [DEBUG] [o.springframework.jndi.JndiTemplate] - Looking up JNDI

因此,看起来jboss在一开始就添加了一些东西.如何预防呢?

So it looks like jboss is adding something at the beginning. How to prevent it ?

推荐答案

WildFly将System.outSystem.err都包装在记录器中.如果要使用写到任一流的追加程序或处理程序,则需要使用java.io.FileDescriptor.out(或err),或者需要为stdoutstderr创建记录器类别以及新的console-handler分配给记录器.

WildFly wraps both System.out and System.err in a logger. If you want to use an appender or handler that writes to either stream you need to either use the java.io.FileDescriptor.out (or err) or you need to create a logger category for stdout or stderr as well as a new console-handler to assign to the logger.

/subsystem=logging/pattern-formatter=stdout:add(pattern="%s%n")
/subsystem=logging/console-handler=stdout:add(autoflush=true, target=System.out, named-formatter=stdout, level=ALL)
/subsystem=logging/logger=stdout:add(use-parent-handlers=false, handlers=[stdout], level=ALL)

上面的CLI脚本应该从记录器stdout中删除默认模式.

The above CLI script should remove the default pattern from the logger stdout.

standalone.xml中的相应表示形式如下:

The corresponding representation in standalone.xml looks like this:

<console-handler name="stdout" autoflush="true">
  <level name="ALL"/>
  <formatter>
    <pattern-formatter pattern="%s%n"/>
  </formatter>
</console-handler>
<logger category="stdout" use-parent-handlers="false">
  <level name="ALL"/>
  <handlers>
    <handler name="stdout"/>
  </handlers>
</logger>

这篇关于登录时,Jboss上的登录会重复前缀和换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆