如何将web应用项目中log4j的日志只打印到独立的文件,不打印在Tomcat的catalina.out?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将web应用项目中log4j的日志只打印到独立的文件,不打印在Tomcat的catalina.out?相关的知识,希望对你有一定的参考价值。

通过log4j的配置文件可以修改打印路径啊追问

这个不是打印路径的问题,是要让日志不重复写入catalina.out中
只在我们设置的日志文件里

参考技术A 右键项目run-as .run-configuration、

选择common。file勾选。选择路径

如何将Hibernate生成的SQL语句打印到日志文件

背景:项目开发需要。

1 操作

只需要在log4j.properties中加入以下两行代码即可

#输出sql语句到日志  
log4j.logger.org.hibernate.SQL=debug  
  
#将对应的参数占位符?换成传入的参数  
log4j.logger.org.hibernate.type=trace

 

实验效果:

2017-09-05 16:51:26 [DubboServerHandler-thread-1] DEBUG org.hibernate.SQL (104) - 
    select
        cpsysparm0_.CODE as CODE65_0_,
        cpsysparm0_.NAME as NAME65_0_,
        cpsysparm0_.PARMVALUE as PARMVALUE65_0_,
        cpsysparm0_.PARMDESC as PARMDESC65_0_,
        cpsysparm0_.MODIFIABLE as MODIFIABLE65_0_,
        cpsysparm0_.VIEWABLE as VIEWABLE65_0_,
        cpsysparm0_.OPERUSER as OPERUSER65_0_,
        cpsysparm0_.OPERTIME as OPERTIME65_0_ 
    from
        CP_SYSPARM cpsysparm0_ 
    where
        cpsysparm0_.CODE=?
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder (83) - binding parameter [1] as [VARCHAR] - 012
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (72) - Found [当前场次             ] as column [NAME65_0_]
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (72) - Found [1] as column [PARMVALUE65_0_]
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (67) - Found [null] as column [PARMDESC65_0_]
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (72) - Found [0] as column [MODIFIABLE65_0_]
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (72) - Found [1] as column [VIEWABLE65_0_]
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (72) - Found [init        ] as column [OPERUSER65_0_]
2017-09-05 16:51:26 [DubboServerHandler-thread-1] TRACE org.hibernate.type.descriptor.sql.BasicExtractor (72) - Found [2011-11-23 10:06:47.0] as column [OPERTIME65_0_]

 

可以看到查询的过程和结果都进行了输出。

 

以上是关于如何将web应用项目中log4j的日志只打印到独立的文件,不打印在Tomcat的catalina.out?的主要内容,如果未能解决你的问题,请参考以下文章

使用log4j如何打印输出到日志文件

日志框架只打印出Mybatis SQL的配置

如何关闭log4j中配置的spring或者hibernate的日志信息

如何将Hibernate生成的SQL语句打印到日志文件

如何使用log4j在日志中打印spring kafka配置

将日志记录添加到独立Java应用程序