使用logbak-spring.xml时,Sring-boot日志文件无法正常运行

时间:2018-06-13 16:18:28

标签: java spring-boot logging logback

我在使用logback-spring.xml和yml属性的spring boot应用程序中工作。 应用程序数据库是一个可以正常运行的AWS DynamoDb。

我的问题在于日志文件和部署跟踪。

当我部署我的应用程序时控制台会显示很多这样的行:

18:01:30,571 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@628a4de1 - URL [**/**/**/logback-spring.xml] is not of type file
18:01:30,575 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
18:01:30,576 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [RollingFile]
18:01:30,578 |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@65ff2151 - No compression will be used
18:01:30,585 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
18:01:30,587 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[RollingFile] - Active log file name: **/**/my_app.log
18:01:30,587 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[RollingFile] - File property is set to [**/**/my_app.log]
18:01:30,596 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework] to DEBUG
18:01:30,597 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating DEBUG level on Logger[org.springframework] onto the JUL framework
18:01:30,598 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.springframework] to false
18:01:30,605 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [RollingFile] to Logger[org.springframework]
18:01:30,607 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [generic.package.of.my.app] to DEBUG
18:01:30,617 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating DEBUG level on Logger[generic.package.of.my.app] onto the JUL framework
18:01:30,662 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [generic.package.of.my.app] to false
18:01:30,662 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [RollingFile] to Logger[generic.package.of.my.app]
18:01:30,664 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [springfox.documentation] to DEBUG
18:01:30,665 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating DEBUG level on Logger[springfox.documentation] onto the JUL framework
18:01:30,665 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [springfox.documentation] to false
18:01:30,666 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [RollingFile] to Logger[springfox.documentation]
18:01:30,667 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.amazonaws] to DEBUG
18:01:30,668 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating DEBUG level on Logger[com.amazonaws] onto the JUL framework
18:01:30,670 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.amazonaws] to false
18:01:30,676 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [RollingFile] to Logger[com.amazonaws]
18:01:30,677 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [weblogic] to DEBUG
18:01:30,679 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating DEBUG level on Logger[weblogic] onto the JUL framework
18:01:30,681 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [weblogic] to false
18:01:30,687 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [RollingFile] to Logger[weblogic]
18:01:30,688 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.socialsignin.spring.data.dynamodb] to DEBUG
18:01:30,689 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating DEBUG level on Logger[org.socialsignin.spring.data.dynamodb] onto the JUL framework
18:01:30,698 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.socialsignin.spring.data.dynamodb] to false
18:01:30,700 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [RollingFile] to Logger[org.socialsignin.spring.data.dynamodb]
18:01:30,702 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
18:01:30,709 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [RollingFile] to Logger[ROOT]
18:01:30,711 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
18:01:30,719 |-INFO in org.springframework.boot.logging.logback.SpringBootJoranConfigurator@49db50ee - Registering current configuration as safe fallback point
18:01:30,721 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating ERROR level on Logger[org.springframework] onto the JUL framework
18:01:30,729 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating TRACE level on Logger[generic.package.of.my.app] onto the JUL framework
18:01:30,731 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating ERROR level on Logger[com.amazonaws] onto the JUL framework
18:01:30,737 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating ERROR level on Logger[org.socialsignin.spring.data.dynamodb] onto the JUL framework
18:01:30,738 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating ERROR level on Logger[springfox.documentation] onto the JUL framework
18:01:30,739 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating ERROR level on Logger[weblogic] onto the JUL framework
18:01:30,741 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@50e48127 - Propagating ERROR level on Logger[ROOT] onto the JUL framewor

顺便说一下,当显示/**/**之类的路径是我不想显示的通用路径时。

此外,日志文件始终打印如下所示的痕迹:

18:01:01.221 [[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG o.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.pattern_level]
18:01:01.222 [[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG o.s.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.pattern_level] not found - trying original name [logging.pattern_level]. javax.naming.NameNotFoundException: While trying to look up comp/env/logging.pattern_level in /app/webapp/my_app.war/1068257839.; remaining name 'comp/env/logging/pattern_level'
18:01:01.222 [[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG o.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging.pattern_level]
18:01:01.222 [[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG o.s.jndi.JndiPropertySource - JNDI lookup for name [logging.pattern_level] threw NamingException with message: While trying to lookup 'logging.pattern_level' didn't find subcontext 'logging'. Resolved ''. Returning null.
18:01:01.222 [[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG o.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.patternLevel]

成千上万的痕迹。

的logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">

    <appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH:-.}/${LOG_FILE:-.}.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>${LOG_PATH:-.}/${LOG_FILE:-.}.%i.log</fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>10</maxIndex>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>30MB</maxFileSize>
        </triggeringPolicy>
        <encoder>
            <pattern>${FILE_LOG_PATTERN:-.}</pattern>
        </encoder>
    </appender>


    <logger name="org.springframework" level="${logging.level.org.springframework}" additivity="false">
        <appender-ref ref="RollingFile"/>
    </logger>
    <logger name="generic.package.of.my.app" level="${generic.package.of.my.app}" additivity="false">
        <appender-ref ref="RollingFile"/>
    </logger>
    <logger name="springfox.documentation" level="${logging.level.springfox.documentation}" additivity="false">
        <appender-ref ref="RollingFile"/>
    </logger>
    <logger name="com.amazonaws" level="${logging.level.com.amazonaws}" additivity="false">
        <appender-ref ref="RollingFile"/>
    </logger>
    <logger name="weblogic" level="${logging.level.weblogic.wsee}" additivity="false">
        <appender-ref ref="RollingFile"/>
    </logger>
    <logger name="org.socialsignin.spring.data.dynamodb" level="${logging.level.com.github.derjust}" additivity="false">
        <appender-ref ref="RollingFile"/>
    </logger>
    <Root level="${logging.level.ROOT}">
        <appender-ref ref="RollingFile"/>
    </Root>

application.yml:

logging:
  file: my_app
  path: /**/**/log
  pattern:
    console: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n"
    file: "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
  level:
    org.springframework: ERROR
    generic.package.of.my.app: TRACE
    springfox.documentation: ERROR
    weblogic: ERROR
    com.amazonaws: ERROR
    org.socialsignin.spring.data.dynamodb: ERROR
    ROOT: ERROR

0 个答案:

没有答案