2017-04-02 6 views
1

나는 log4j2 구성을 XML로 작성했습니다. 그러나 배열 목적으로 속성 형식 (키와 값)으로 작성해야합니다. 중첩 된 조건을 XML 속성에 매핑 할 수 없습니다. 여기 log4j2 매핑 XML을 속성 파일

내 XML 구성입니다 :

<?xml version="1.0" encoding="UTF-8"?> 
<Configuration status="DEBUG"> 
    <Properties> 
     <Property name="log-path">./var/log/reporter/</Property> 
    </Properties> 
    <Appenders> 

     <RollingFile name="RollingFile" fileName="${log-path}/reporter.log" 
      filePattern="${log-path}/reporter-%d{yyyy-MM-dd}-%i.log"> 
      <PatternLayout> 
       <pattern>[Reporter] [%level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%logger{36}] %msg%n</pattern> 
      </PatternLayout> 
      <Policies> 
       <TimeBasedTriggeringPolicy interval="1" modulate="true" /> 
       <SizeBasedTriggeringPolicy size="20 MB" /> 
      </Policies> 
      <DefaultRolloverStrategy max = "1000"> 
       <Delete basePath="${log-path}"> 
        <IfFileName glob="reporter-*.log" /> 
        <IfAny> 
         <IfLastModified age="90D" /> 
         <IfAccumulatedFileSize exceeds="2 GB" /> 
        </IfAny> 
       </Delete> 
      </DefaultRolloverStrategy> 
     </RollingFile> 

    </Appenders> 
    <Loggers> 
     <Logger name="root" level="debug" additivity="false"> 
      <appender-ref ref="RollingFile" level="debug" /> 
     </Logger> 
     <Root level="debug" additivity="false"> 
      <AppenderRef ref="RollingFile" /> 
     </Root> 
    </Loggers> 
</Configuration> 

그리고 여기 내 비 작업 속성 구성 매핑 : 조금 늦게

appender.rolling.type = RollingFile 
appender.rolling.name = RollingFile 
appender.rolling.fileName = ${logpath}/reporter.log 
appender.rolling.filePattern = ${logpath}/reporter-%d{yyyy-MM-dd}-%i.log 
appender.rolling.layout.type = PatternLayout 
appender.rolling.layout.pattern = [Reporter] [%level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%logger{36}] %msg%n 
appender.rolling.policies.type = Policies 
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy 
appender.rolling.policies.time.interval = 1 
appender.rolling.policies.time.modulate = true 
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy 
appender.rolling.policies.size.size=1KB 
appender.rolling.strategy.type = DefaultRolloverStrategy 
appender.rolling.strategy.max = 1000 
appender.rolling.strategy.action.type = Delete 
appender.rolling.strategy.action.basepath = ${logpath} 
appender.rolling.strategy.action.NestedConditions.type = IfALL 
appender.rolling.strategy.action.NestedConditions.PathConditions.type = IfFileName 
appender.rolling.strategy.action.NestedConditions.PathConditions.glob = reporter-*.log 
appender.rolling.strategy.action.NestedConditions.NestedConditions.type = IfAny 
appender.rolling.strategy.action.NestedConditions.NestedConditions.time.type = IfLastModified 
appender.rolling.strategy.action.NestedConditions.NestedConditions.time.age = 90D 
appender.rolling.strategy.action.NestedConditions.NestedConditions.size.type = IfAccumulatedFileSize 
appender.rolling.strategy.action.NestedConditions.NestedConditions.size.age = 2GB 

logger.rolling.name = root 
logger.rolling.level = debug 
logger.rolling.additivity = false 
logger.rolling.appenderRef.rolling.ref = RollingFile 

rootLogger.level = debug 
rootLogger.appenderRef.stdout.ref = RollingFile 
+0

모하메드, 속성에 XML을 매핑 할 수 있었습니까? 나는 비슷한 상황에 처해있다 .. – rouslanm

+0

불행히도 우리는 결국 속성 파일을 사용했다. –

+0

속성 파일을 사용한 경우 여러 중첩 조건을 어떻게 관리 했습니까? 중첩 된 조건이 하나만있는 경우 elifyilbasi의 대답은 일치하지만 두 개 이상있는 경우 결과 속성은 이전 중첩 조건의 복제본처럼 보이므로 작동하지 않습니다. – rouslanm

답변