英文:
logback.xml in spring boot not printing debug messages
问题
New to logback. I'm trying to print debug and info messages to external file.
I'm reading the configuration from this file
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="HOME_LOG" value="C:\Users\Usuario\Desktop\SH_DashboardCES\Logs\Dashboard.log"/>
<appender name="FILE-ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${HOME_LOG}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>logs/archived/app.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<!-- each archived file, size max 10MB -->
<maxFileSize>10MB</maxFileSize>
<!-- total size of all archive files, if total size > 20GB, it will delete old archived file -->
<totalSizeCap>20GB</totalSizeCap>
<!-- 60 days to keep -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d %p %c{1.} [%t] %m%n</pattern>
</encoder>
</appender>
<logger name="pe.com.dashboard" level="DEBUG" additivity="false">
<appender-ref ref="FILE-ROLLING"/>
</logger>
<root level="ERROR">
<appender-ref ref="FILE-ROLLING"/>
</root>
</configuration>
Printed Dashboard.log
2020-04-06 16:18:37,362 INFO pe.com.claro.postventa.dashboard.Application [main] Starting Application v1.0.0 on HPERLAPVALDK with PID 17808 (C:\Users\Usuario\Desktop\SH_DashboardCES\Dashboard-1.0.0.jar started by valdezkj in C:\Users\Usuario\Desktop\SH_DashboardCES)
2020-04-06 16:18:37,365 DEBUG pe.com.claro.postventa.dashboard.Application [main] Running with Spring Boot v2.2.5.RELEASE, Spring v5.2.4.RELEASE
2020-04-06 16:18:37,365 INFO pe.com.claro.postventa.dashboard.Application [main] No active profile set, falling back to default profiles: default
2020-04-06 16:18:52,651 INFO pe.com.claro.postventa.dashboard.Application [main] Started Application in 15.828 seconds (JVM running for 16.296)
Java Class implementing logback
package pe.com.dashboard.dao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
import java.util.*;
@Repository
public class ClarifyDaoImpl implements ClarifyDao {
Logger logger = LoggerFactory.getLogger(ClarifyDaoImpl.class);
@Override
public ConsultaTipificacionOutputMapper consultaTipificacion(ConsultaTipificacionInputMapper request) throws DBException {
logger.info(INICIO_TRANSACCION + nombreMetodo);
logger.debug(INPUT_PARAMETERS + request.toString());
return null;
}
}
None of the messages in the java class is printed even when the log level of the package is set to DEBUG.
英文:
New to logback. I'm trying to print debug and info messages to external file.
I'm reading the configuration from this file
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="HOME_LOG" value="C:\\Users\\Usuario\\Desktop\\SH_DashboardCES\\Logs\\Dashboard.log"/>
<appender name="FILE-ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${HOME_LOG}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>logs/archived/app.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<!-- each archived file, size max 10MB -->
<maxFileSize>10MB</maxFileSize>
<!-- total size of all archive files, if total size > 20GB, it will delete old archived file -->
<totalSizeCap>20GB</totalSizeCap>
<!-- 60 days to keep -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d %p %c{1.} [%t] %m%n</pattern>
</encoder>
</appender>
<logger name="pe.com.dashboard" level="DEBUG" additivity="false">
<appender-ref ref="FILE-ROLLING"/>
</logger>
<root level="ERROR">
<appender-ref ref="FILE-ROLLING"/>
</root>
</configuration>
Printed Dashboard.log
2020-04-06 16:18:37,362 INFO pe.com.claro.postventa.dashboard.Application [main] Starting Application v1.0.0 on HPERLAPVALDK with PID 17808 (C:\Users\Usuario\Desktop\SH_DashboardCES\Dashboard-1.0.0.jar started by valdezkj in C:\Users\Usuario\Desktop\SH_DashboardCES)
2020-04-06 16:18:37,365 DEBUG pe.com.claro.postventa.dashboard.Application [main] Running with Spring Boot v2.2.5.RELEASE, Spring v5.2.4.RELEASE
2020-04-06 16:18:37,365 INFO pe.com.claro.postventa.dashboard.Application [main] No active profile set, falling back to default profiles: default
2020-04-06 16:18:52,651 INFO pe.com.claro.postventa.dashboard.Application [main] Started Application in 15.828 seconds (JVM running for 16.296)
Java Class implementing logback
package pe.com.dashboard.dao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
import java.util.*;
@Repository
public class ClarifyDaoImpl implements ClarifyDao {
Logger logger = LoggerFactory.getLogger(ClarifyDaoImpl.class);
@Override
public ConsultaTipificacionOutputMapper consultaTipificacion(ConsultaTipificacionInputMapper request) throws DBException {
logger.info(INICIO_TRANSACCION + nombreMetodo);
logger.debug(INPUT_PARAMETERS + request.toString());
return null;
}
}
None of the messages in the java class is printed even when the log level of the package is set to DEBUG.
答案1
得分: -1
<root level="ERROR">
<appender-ref ref="FILE-ROLLING"/>
</root>
日志级别:跟踪 < 调试 < 信息 < 警告 < 错误
您可以将级别更改为调试。
英文:
<root level="ERROR">
<appender-ref ref="FILE-ROLLING"/>
</root>
log level : trace < debug < info < warn < Error
you can change level to debug
专注分享java语言的经验与见解,让所有开发者获益!
评论