Springboot应用程序上的Log4j2配置

时间:2020-08-04 01:14:30

标签: spring-boot log4j2

我具有以下配置,该配置可以在没有引发任何异常的情况下中断我的Spring启动应用程序,而且我无法弄清楚它出了什么问题

            <?xml version="1.0" encoding="UTF-8"?>
        <Configuration>
          <Appenders>

            <!-- Rolling File Appender -->
            <RollingFile name="JMSLOGFILE">
              <FileName>/some/path/to/log_jms.log</FileName>
              <filePattern>/some/path/to/log_jms.log.%d{}.%i</filePattern>
              <PatternLayout>
                <Pattern>%d{yyyy-MMM-dd HH:mm:ss a} ${hostName} %-5level %c{0} - %msg%n</Pattern>
              </PatternLayout>
              <Policies>
                <SizeBasedTriggeringPolicy size="10MB"/>
              </Policies>
              <DefaultRolloverStrategy max="5" />
            </RollingFile>
            
            <RollingFile name="SOMELOGFILE">
              <FileName>/some/path/to/log.log</FileName>
              <filePattern>/some/path/to/log.log.%d{}.%i</filePattern>
              <PatternLayout>
                <Pattern>%d{yyyy-MMM-dd HH:mm:ss a} ${hostName} %-5level %c{0} - %msg%n</Pattern>
              </PatternLayout>
              <Policies>
                <SizeBasedTriggeringPolicy size="10MB"/>
              </Policies>
              <DefaultRolloverStrategy max="5" />
            </RollingFile>
            
            <RollingFile name="HIBERNATELOGFILE">
              <FileName>/some/path/to/logHibernate.log</FileName>
              <filePattern>/some/path/to/logHibernate.log.%d{}.%i</filePattern>
              <PatternLayout>
                <Pattern>%d{yyyy-MMM-dd HH:mm:ss a} ${hostName} %-5level %c{0} - %msg%n</Pattern>
              </PatternLayout>
              <Policies>
                <SizeBasedTriggeringPolicy size="10MB"/>
              </Policies>
              <DefaultRolloverStrategy max="5" />
            </RollingFile>  
            
            <RollingFile name="ENTITLEMENTLOGFILE">
              <FileName>/some/path/to/log_entitlements.log</FileName>
              <filePattern>/some/path/to/log_entitlements.log.%d{}.%i</filePattern>
              <PatternLayout>
                <Pattern>%d{yyyy-MMM-dd HH:mm:ss a} ${hostName} %-5level %c{0} - %msg%n</Pattern>
              </PatternLayout>
              <Policies>
                <SizeBasedTriggeringPolicy size="10MB"/>
              </Policies>
              <DefaultRolloverStrategy max="5" />
            </RollingFile>

            <RollingFile name="DALLOGFILE">
              <FileName>/some/path/to/logDal.log</FileName>
              <filePattern>/some/path/to/logDal.log.%d{}.%i</filePattern>
              <PatternLayout>
                <Pattern>%d{yyyy-MMM-dd HH:mm:ss a} ${hostName} %-5level %c{0} - %msg%n</Pattern>
              </PatternLayout>
              <Policies>
                <SizeBasedTriggeringPolicy size="10MB"/>
              </Policies>
              <DefaultRolloverStrategy max="5" />
            </RollingFile>

            
          </Appenders>
          <Loggers>
            <Logger name="_xxxPortal" level="INFO" additivity="false">
              <AppenderRef ref="SOMELOGFILE" />
            </Logger>
            <Logger name="portlets" level="INFO" additivity="false">
              <AppenderRef ref="SOMELOGFILE" />
            </Logger>
            <Logger name="com.company.rft" level="INFO" additivity="false">
              <AppenderRef ref="SOMELOGFILE" />
            </Logger>   
            <Logger name="com.company.tas" level="INFO" additivity="false">
              <AppenderRef ref="SOMELOGFILE" />
            </Logger>   
            <Logger name="com.company.gcrm.dal" level="INFO" additivity="false">
              <AppenderRef ref="DALLOGFILE" />
            </Logger>   
            <Logger name="org.hibernate" level="INFO" additivity="false">
              <AppenderRef ref="HIBERNATELOGFILE" />
            </Logger>
            <Logger name="org.hibernate.SQL" level="WARN" additivity="false">
              <AppenderRef ref="HIBERNATELOGFILE" />
            </Logger>
            <Logger name="net.sf.hibernate" level="WARN" additivity="false">
              <AppenderRef ref="HIBERNATELOGFILE" />
            </Logger>
            <Logger name="backing.DesktopBacking" level="INFO" additivity="false">
              <AppenderRef ref="SOMELOGFILE" />
            </Logger>
            <Logger name="com.company.package1" level="WARN" additivity="false">
              <AppenderRef ref="ENTITLEMENTLOGFILE" />
            </Logger>
            <Logger name="com.company.package2.entitlements" level="INFO" additivity="false">
              <AppenderRef ref="ENTITLEMENTLOGFILE" />
            </Logger>
            <Logger name="org.springframework.jdbc" level="INFO" additivity="false">
              <AppenderRef ref="SOMELOGFILE" />
            </Logger>
            <Logger name="org.springframework.jms" level="INFO" additivity="false">
              <AppenderRef ref="JMSLOGFILE" />
            </Logger>
            <Root level="FATAL">
              <AppenderRef ref="SOMELOGFILE" />
            </Root>
          </Loggers>
        </Configuration>

此外,我希望命名模式类似于logFile.log。{index},我在另一个应用程序上尝试过logFile.log。%i,除非我先输入日期,否则它也会中断,这在这里不起作用

0 个答案:

没有答案