Мне нужно поместить этот файл log4j2-spring.xml
вне моей упаковки.Я настраиваю в своем application.properties следующую строку:
logging.config=C:\\example\\apache-tomcat-8.0.20\\webapps\\log4j2-spring.xml
Мой log4j2.xml создает папку "logs" внутри "C: \ example \ apache-tomcat-8.0.20 \ webapps \".Когда я использую этот файл внутри своих ресурсов, работает отлично, но когда я использую снаружи, не работает.
Как я могу это сделать?
РЕДАКТИРОВАТЬ:
<Appenders>
<RollingFile name="TraceAppender" fileName="C:/example/apache-tomcat-8.0.20/webapps/logs/Trace.log"
filePattern="C:/example/apache-tomcat-8.0.20/webapps/logs/Trace-%d{yyyy-MM-dd}.log.gz"
append="true">
<Filters>
<ThresholdFilter level="TRACE" />
<ThresholdFilter level="DEBUG" onMatch="DENY"
onMismatch="NEUTRAL" />
<ThresholdFilter level="INFO" onMatch="DENY"
onMismatch="NEUTRAL" />
<ThresholdFilter level="WARN" onMatch="DENY"
onMismatch="NEUTRAL" />
<ThresholdFilter level="ERROR" onMatch="DENY"
onMismatch="NEUTRAL" />
</Filters>
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] (%C:%M:%L) - %m%n" />
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<DefaultRolloverStrategy>
<Delete basePath="C:/example/apache-tomcat-8.0.20/webapps/logs/">
<IfFileName glob="Trace-*.log.gz" />
<IfLastModified age="P28D" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<RollingFile name="DebugAppender" fileName="C:/example/apache-tomcat-8.0.20/webapps/logs/Debug.log"
filePattern="C:/example/apache-tomcat-8.0.20/webapps/logs/Debug-%d{yyyy-MM-dd}.log.gz"
append="true">
<Filters>
<ThresholdFilter level="DEBUG" />
<ThresholdFilter level="INFO" onMatch="DENY"
onMismatch="NEUTRAL" />
<ThresholdFilter level="WARN" onMatch="DENY"
onMismatch="NEUTRAL" />
<ThresholdFilter level="ERROR" onMatch="DENY"
onMismatch="NEUTRAL" />
</Filters>
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] (%C:%M:%L) - %m%n" />
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<DefaultRolloverStrategy>
<Delete basePath="C:/example/apache-tomcat-8.0.20/webapps/logs/">
<IfFileName glob="Debug-*.log.gz" />
<IfLastModified age="P28D" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<RollingFile name="DebugControllerAppender"
fileName="C:/example/apache-tomcat-8.0.20/webapps/logs/DebugController.log"
filePattern="C:/example/apache-tomcat-8.0.20/webapps/logs/DebugController-%d{yyyy-MM-dd}.log.gz"
append="true">
<Filters>
<ThresholdFilter level="DEBUG" />
<ThresholdFilter level="INFO" onMatch="DENY"
onMismatch="NEUTRAL" />
<ThresholdFilter level="WARN" onMatch="DENY"
onMismatch="NEUTRAL" />
<ThresholdFilter level="ERROR" onMatch="DENY"
onMismatch="NEUTRAL" />
</Filters>
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] (%C:%M:%L) - %m%n" />
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<DefaultRolloverStrategy>
<Delete basePath="C:/example/apache-tomcat-8.0.20/webapps/logs/">
<IfFileName glob="DebugController-*.log.gz" />
<IfLastModified age="P28D" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<RollingFile name="InfoAppender" fileName="C:/example/apache-tomcat-8.0.20/webapps/logs/Info.log"
filePattern="C:/example/apache-tomcat-8.0.20/webapps/logs/Info-%d{yyyy-MM-dd}.log.gz"
append="true">
<Filters>
<ThresholdFilter level="INFO" />
<ThresholdFilter level="WARN" onMatch="DENY"
onMismatch="NEUTRAL" />
<ThresholdFilter level="ERROR" onMatch="DENY"
onMismatch="NEUTRAL" />
</Filters>
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] (%C:%M:%L) - %m%n" />
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<DefaultRolloverStrategy>
<Delete basePath="C:/example/apache-tomcat-8.0.20/webapps/logs/">
<IfFileName glob="Info-*.log.gz" />
<IfLastModified age="P28D" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<RollingFile name="WarnAppender" fileName="C:/example/apache-tomcat-8.0.20/webapps/logs/Warn.log"
filePattern="C:/example/apache-tomcat-8.0.20/webapps/logs/Warn-%d{yyyy-MM-dd}.log.gz"
append="true">
<Filters>
<ThresholdFilter level="WARN" onMatch="ACCEPT"
onMismatch="DENY" />
<ThresholdFilter level="ERROR" onMatch="DENY"
onMismatch="NEUTRAL" />
</Filters>
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] (%C:%M:%L) - %m%n" />
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<DefaultRolloverStrategy>
<Delete basePath="C:/example/apache-tomcat-8.0.20/webapps/logs/">
<IfFileName glob="Warn-*.log.gz" />
<IfLastModified age="P28D" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<RollingFile name="ErrorAppender" fileName="C:/example/apache-tomcat-8.0.20/webapps/logs/Error.log"
filePattern="C:/example/apache-tomcat-8.0.20/webapps/logs/Error-%d{yyyy-MM-dd}.log.gz"
append="true">
<ThresholdFilter level="ERROR" />
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] (%C:%M:%L) - %m%n" />
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<DefaultRolloverStrategy>
<Delete basePath="C:/example/apache-tomcat-8.0.20/webapps/logs/">
<IfFileName glob="Error-*.log.gz" />
<IfLastModified age="P28D" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<RollingFile name="AllLogsAppender" fileName="C:/example/apache-tomcat-8.0.20/webapps/logs/All.log"
filePattern="C:/example/apache-tomcat-8.0.20/webapps/logs/All-%d{yyyy-MM-dd}.log.gz"
append="true">
<ThresholdFilter level="ALL" />
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] (%C:%M:%L) - %m%n" />
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<DefaultRolloverStrategy>
<Delete basePath="C:/example/apache-tomcat-8.0.20/webapps/logs/">
<IfFileName glob="All-*.log.gz" />
<IfLastModified age="P28D" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<RollingFile name="HibernateAppender" fileName="C:/example/apache-tomcat-8.0.20/webapps/logs/Hibernate.log"
filePattern="C:/example/apache-tomcat-8.0.20/webapps/logs/Hibernate-%d{yyyy-MM-dd}.log.gz"
append="true">
<ThresholdFilter level="ERROR" onMatch="ACCEPT"
onMismatch="DENY" />
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] (%C:%M:%L) - %m%n" />
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<DefaultRolloverStrategy>
<Delete basePath="C:/example/apache-tomcat-8.0.20/webapps/logs/">
<IfFileName glob="Hibernate-*.log.gz" />
<IfLastModified age="P28D" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<RollingFile name="SpringAppender" fileName="C:/example/apache-tomcat-8.0.20/webapps/logs/Spring.log"
filePattern="C:/example/apache-tomcat-8.0.20/webapps/logs/Spring-%d{yyyy-MM-dd}.log.gz"
append="true">
<ThresholdFilter level="ERROR" onMatch="ACCEPT"
onMismatch="DENY" />
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t] (%C:%M:%L) - %m%n" />
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<DefaultRolloverStrategy>
<Delete basePath="C:/example/apache-tomcat-8.0.20/webapps/logs/">
<IfFileName glob="Spring-*.log.gz" />
<IfLastModified age="P28D" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<Console name="Console">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="org.springframework" level="WARN">
<AppenderRef ref="TraceAppender" />
<AppenderRef ref="ErrorAppender" />
<AppenderRef ref="SpringAppender" />
</Logger>
<Logger name="org.hibernate" level="WARN">
<AppenderRef ref="TraceAppender" />
<AppenderRef ref="ErrorAppender" />
<AppenderRef ref="HibernateAppender" />
</Logger>
<Logger name="es.example">
<AppenderRef ref="ErrorAppender" />
<AppenderRef ref="WarnAppender" />
<AppenderRef ref="DebugAppender" />
<AppenderRef ref="InfoAppender" />
</Logger>
<Logger name="es.example.glusilo.controller">
<AppenderRef ref="DebugControllerAppender" />
</Logger>
<Logger name="com.mchange" level="WARN" />
<Logger name="net.sf.ehcache" level="WARN" />
<!-- All logs will be placed here (${log4j.logs.path}/All.log), from each
library, yours included -->
<Root level="INFO">
<AppenderRef ref="AllLogsAppender" />
<AppenderRef ref="Console" />
</Root>
</Loggers>