log4j2 支持指定哪些包输出, 禁止hibernate等第三方的logger日志输出

版权声明:本文地址http://blog.csdn.net/caib1109/article/details/51407091
欢迎非商业目的的转载, 作者保留一切权利

友情提醒: log4j2需要jdk版本大于等于7, 对于还在用Java6的服务器来说不兼容. 如果在已有项目中进行服务器后端开发, 请继续使用log4j

log4j2的.xml的配置文件, 支持指定哪些包输出, .properties的配置文件没试过.

http://logging.apache.org/log4j/2.x/manual/configuration.html#Additivity

Additivity

Perhaps it is desired to eliminate all the TRACE output from everything except com.foo.Bar. Simply changing the log level would not accomplish the task. Instead, the solution is to add a new logger definition to the configuration:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <!--制定输出com.foo包中的logger, 忽略其他logger-->
    <Logger name="com.foo" level="trace"> 
      <AppenderRef ref="Console"/>
    </Logger>
    <Root level="error">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>

http://logging.apache.org/log4j/2.x/manual/configuration.html#ConfigurationSyntax

Configuration Syntax
As the previous examples have shown as well as those to follow, Log4j allows you to easily redefine logging behavior without needing to modify your application. It is possible to disable logging for certain parts of the application

如前文所述, log4j 允许你在不修改程序代码的前提下, 重新定义logging的行为. 禁止程序某些部分的日志输出是可行的.

版权声明:本文地址http://blog.csdn.net/caib1109/article/details/51407091
欢迎非商业目的的转载, 作者保留一切权利

你可能感兴趣的:(java,log4j,Hibernate)