logback.xml在Spring Boot中不打印调试信息。

huangapple 未分类评论45阅读模式
英文:

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

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;configuration&gt;

    &lt;property name=&quot;HOME_LOG&quot; value=&quot;C:\\Users\\Usuario\\Desktop\\SH_DashboardCES\\Logs\\Dashboard.log&quot;/&gt;

    &lt;appender name=&quot;FILE-ROLLING&quot; class=&quot;ch.qos.logback.core.rolling.RollingFileAppender&quot;&gt;
        &lt;file&gt;${HOME_LOG}&lt;/file&gt;

        &lt;rollingPolicy class=&quot;ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy&quot;&gt;
            &lt;fileNamePattern&gt;logs/archived/app.%d{yyyy-MM-dd}.%i.log.gz&lt;/fileNamePattern&gt;
            &lt;!-- each archived file, size max 10MB --&gt;
            &lt;maxFileSize&gt;10MB&lt;/maxFileSize&gt;
            &lt;!-- total size of all archive files, if total size &gt; 20GB, it will delete old archived file --&gt;
            &lt;totalSizeCap&gt;20GB&lt;/totalSizeCap&gt;
            &lt;!-- 60 days to keep --&gt;
            &lt;maxHistory&gt;60&lt;/maxHistory&gt;
        &lt;/rollingPolicy&gt;

        &lt;encoder&gt;
            &lt;pattern&gt;%d %p %c{1.} [%t] %m%n&lt;/pattern&gt;
        &lt;/encoder&gt;
    &lt;/appender&gt;

    &lt;logger name=&quot;pe.com.dashboard&quot; level=&quot;DEBUG&quot; additivity=&quot;false&quot;&gt;
        &lt;appender-ref ref=&quot;FILE-ROLLING&quot;/&gt;
    &lt;/logger&gt;

    &lt;root level=&quot;ERROR&quot;&gt;
        &lt;appender-ref ref=&quot;FILE-ROLLING&quot;/&gt;
    &lt;/root&gt;

&lt;/configuration&gt;

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

&lt;root level=&quot;ERROR&quot;&gt;
        &lt;appender-ref ref=&quot;FILE-ROLLING&quot;/&gt;
&lt;/root&gt;

日志级别:跟踪 < 调试 < 信息 < 警告 < 错误

您可以将级别更改为调试。

英文:
&lt;root level=&quot;ERROR&quot;&gt;
        &lt;appender-ref ref=&quot;FILE-ROLLING&quot;/&gt;
&lt;/root&gt;

log level : trace < debug < info < warn < Error

you can change level to debug

huangapple
  • 本文由 发表于 2020年4月7日 05:24:37
  • 转载请务必保留本文链接:https://java.coder-hub.com/61069217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定