我有一个带Hibernate的Spring应用程序(不是Sping Boot !!!)。Spring框架版本是5.3.26。Hibernate版本是5.6.14.Final
<!-- Logging dependencies -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.4.6</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.6</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.7</version>
</dependency>
实际上,我想将与应用程序相关的类作为DEBUG +所有其他类(spring,flyway,poi等)记录到一个文件中,并将与SQL相关的类记录到另一个文件中。这是logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<property name="LOGS" value="${APP_HOME}/logs" />
<appender name="RollingFileAll"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/all.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOGS}/%d{yyyy-MM, aux}/all-%d{yyyy-MM-dd}.log.gz
</fileNamePattern>
<maxHistory>60</maxHistory>
<totalSizeCap>250MB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="RollingFileSql"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/sql.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSSXXX} %p %c{3} [%t] user=%X{userName} %m%n</Pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOGS}/%d{yyyy-MM, aux}/sql-%d{yyyy-MM-dd}.log.gz
</fileNamePattern>
<maxHistory>60</maxHistory>
<totalSizeCap>250MB</totalSizeCap>
</rollingPolicy>
</appender>
<!-- LOG "application classes" at debug level -->
<logger name="com.Application.cctng" level="debug" additivity="false">
<appender-ref ref="RollingFileAll" />
</logger>
<logger name="org.hibernate.SQL" level="debug" additivity="false" >
<appender-ref ref="RollingFileSql" />
</logger>
<logger name="org.hibernate.type.descriptor.sql" level="trace" additivity="false" >
<appender-ref ref="RollingFileSql" />
</logger>
<logger name="org.hibernate.stat" level="debug" additivity="false">
<appender-ref ref="RollingFileSql"/>
</logger>
<logger name="org.hibernate.SQL_SLOW" level="info" additivity="false">
<appender-ref ref="RollingFileSql"/>
</logger>
<logger name="org.hibernate.cache" level="debug" additivity="false">
<appender-ref ref="RollingFileSql"/>
</logger>
<!-- LOG everything at INFO level-->
<root level="info" >
<appender-ref ref="RollingFileAll" />
</root>
</configuration>
但是sql日志文件完全是空的,而应用程序相关的日志工作正常。
1条答案
按热度按时间ccrfmcuu1#
JBoss日志记录尝试查找适当的日志记录提供程序。
org.jboss.logging.provider
。这意味着,对我来说,解决方案是将
-Dorg.jboss.logging.provider="slf4j"
设置为JVM选项。