简体   繁体   English

如何使用 logback 记录 org.springframework.web.context.ContextLoader

[英]How to log org.springframework.web.context.ContextLoader with logback

I have little problem with logging Spring bootstrap.我对记录 Spring bootstrap 没有什么问题。 I cant log org.springframework.web.context.ContextLoader with logback.我无法使用 logback 记录 org.springframework.web.context.ContextLoader。 Can someone give a point how to log Spring boot?有人可以指出如何登录 Spring Boot 吗?

Here is my logback.xml这是我的 logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- load props file -->
    <define name="propExists" class="ch.qos.logback.core.property.ResourceExistsPropertyDefiner">
        <resource>META-INF/crdb.prod.properties</resource>
    </define>
    <if condition='${propExists}'>
        <then><property resource="META-INF/crdb.prod.properties" /></then>
    </if>
    <define name="propExists" class="ch.qos.logback.core.property.ResourceExistsPropertyDefiner">
        <resource>META-INF/crdb.test.properties</resource>
    </define>
    <if condition='${propExists}'>
        <then><property resource="META-INF/crdb.test.properties" /></then>
    </if>
    <define name="propExists" class="ch.qos.logback.core.property.ResourceExistsPropertyDefiner">
        <resource>META-INF/crdb.dev.properties</resource>
    </define>
    <if condition='${propExists}'>
        <then><property resource="META-INF/crdb.dev.properties" /></then>
    </if>

    <!-- Send debug messages to System.out -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- By default, encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] [%X{distribute_trace_id}] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- Send debug messages to a file -->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${catalina.home}/logs/crdb.log</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%thread] [%X{distribute_trace_id}] %-5level %logger{36} - %msg%n</Pattern>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <FileNamePattern>${catalina.home}/logs/crdb.%i.log.zip</FileNamePattern>
            <MinIndex>1</MinIndex>
            <MaxIndex>10</MaxIndex>
        </rollingPolicy>

        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>2MB</MaxFileSize>
        </triggeringPolicy>
    </appender>

    <property name="APP_VERSION" value="1.2.1"/>

    <!-- max size of the log file, when the log file will be bigger, then will be split -->
    <property name="LOG_FILE_MAX_SIZE" value="200MB"/>
    <!-- max size of logs in ALL log files -->
    <property name="LOG_TOTAL_SIZE_CAP" value="1GB"/>
    <!-- count of days - files will be persisted for these days -->
    <property name="LOG_FILE_MAX_HISTORY" value="3"/>

    <!-- Splunk Monitoring Messages -->
    <appender name="SPLUNK_MONITORING" class="ch.qos.logback.core.rolling.RollingFileAppender" additivity="false">
        <file>${catalina.home}/logs/splunk_monitoring/crdb.log</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>%msg%n</Pattern>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!-- daily rollover inferred from the file name -->
            <fileNamePattern>${catalina.home}/logs/splunk_monitoring/crdb.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>${LOG_FILE_MAX_SIZE}</maxFileSize>
            <maxHistory>${LOG_FILE_MAX_HISTORY}</maxHistory>
            <totalSizeCap>${LOG_TOTAL_SIZE_CAP}</totalSizeCap>
        </rollingPolicy>
    </appender>

    <appender name="SPLUNK_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${catalina.home}/logs/splunk/crdb.log</file>
        <encoder class="net.logstash.logback.encoder.LogstashEncoder">
            <version>${APP_VERSION}</version>
            <timestampPattern>yyyy-MM-dd'T'HH:mm:ss.SSS</timestampPattern>
            <customFields>{"app_name":"CRDB", "env": "${env.key}", "hostname": "${hostname}"}</customFields>
            <fieldNames>
                <timestamp>time</timestamp>
                <version>app_version</version>
                <levelValue>[ignore]</levelValue>
            </fieldNames>
            <throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
                <exclude>net\.sf\.cglib\..*</exclude>
                <maxDepthPerThrowable>30</maxDepthPerThrowable>
                <rootCauseFirst>true</rootCauseFirst>
            </throwableConverter>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!-- daily rollover inferred from the file name -->
            <fileNamePattern>${catalina.home}/logs/splunk/crdb.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>${LOG_FILE_MAX_SIZE}</maxFileSize>
            <maxHistory>${LOG_FILE_MAX_HISTORY}</maxHistory>
            <totalSizeCap>${LOG_TOTAL_SIZE_CAP}</totalSizeCap>
        </rollingPolicy>
    </appender>

    <logger name="splunk_monitoring" level="INFO" additivity="false">
        <appender-ref ref="SPLUNK_MONITORING"/>
    </logger>

    <logger name="org.springframework.web.context.*" level="INFO" additivity="false">
        <appender-ref ref="STDOUT"/>
    </logger>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="FILE"/>
        <appender-ref ref="SPLUNK_FILE"/>
    </root>
</configuration>

When I try this configuration, It only write to console, that log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).当我尝试此配置时,它只写入控制台,即 log4j:WARN 找不到记录器的附加程序(org.springframework.web.context.ContextLoader)。 log4j:WARN Please initialize the log4j system properly. log4j:WARN 请正确初始化 log4j 系统。 Thank you.谢谢你。

Tried this ?试过这个吗?

<logger name="org.springframework.web">
<level value="info" /> 
<appender-ref ref="console" />     
</logger>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:org.springframework.web.context.ContextLoader - 上下文初始化失败 - ERROR: org.springframework.web.context.ContextLoader - Context initialization failed 错误:org.springframework.web.context.ContextLoader-上下文初始化失败org.springframework.beans.factory.BeanCreationException - ERROR: org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException 错误:org.springframework.web.context.ContextLoader-上下文初始化失败[context-security.xml] - ERROR: org.springframework.web.context.ContextLoader - Context initialization failed [context-security.xml] 春季错误:org.springframework.web.context.ContextLoader-上下文初始化失败 - spring error :org.springframework.web.context.ContextLoader - Context initialization failed 码头:错误[org.springframework.web.context.ContextLoader:215]-上下文初始化失败 - Jetty: ERROR [org.springframework.web.context.ContextLoader:215] - Context initialization failed 无法在 macOS 上使用 tomcat 部署应用程序:org.springframework.web.context.ContextLoader.initWebApplicationContext 上下文初始化失败 - Cannot deploy app using tomcat on macOS: org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed org.springframework.web.context.ContextLoaderListener类notfoundexception - org.springframework.web.context.ContextLoaderListener classnotfoundexception ClassNotFoundException:org.springframework.web.context.ContextLoaderListener - ClassNotFoundException: org.springframework.web.context.ContextLoaderListener org.springframework.boot.context.event.ApplicationFailedEvent无法转换为org.springframework.boot.web.context.WebServerInitializedEvent - org.springframework.boot.context.event.ApplicationFailedEvent cannot be cast to org.springframework.boot.web.context.WebServerInitializedEvent org.springframework.web.context.ContextLoaderListener(java.lang.ClassNotFoundException) - org.springframework.web.context.ContextLoaderListener(java.lang.ClassNotFoundException)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM