首页 > eclipse下起的项目,使用log4j2记录日志,想让日志输出到项目文件夹下,却总是输出到eclipse文件夹下,求大神赐教

eclipse下起的项目,使用log4j2记录日志,想让日志输出到项目文件夹下,却总是输出到eclipse文件夹下,求大神赐教

log4j2.xml:






<properties>
   <property name="filenameLog">logs/payPlatform.log</property>
</properties>

 <!-- 定义后台文档日志记录 -->
<RollingFile name="RollingFile" fileName="${filenameLog}" filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">  
    <PatternLayout>  
        <Pattern>%d{yyyy-MM-dd HH:mm:ss} [%p] [%t] %c{1}.%M(%L) | %m%n</Pattern>  
    </PatternLayout>  
    <Policies>
        <!-- 定义log文件封存的周期 -->  
        <TimeBasedTriggeringPolicy interval="1" modulate="true" />  
        <SizeBasedTriggeringPolicy size="100 MB"/>  
    </Policies>  
    <DefaultRolloverStrategy fileIndex="max" max="2"/>  
</RollingFile>  






<!-- 定义除单个类外所有日志记录级别 -->  
<Root level="trace">
    <AppenderRef ref="Console"/>
    <AppenderRef ref="RollingFile"/>
</Root>  


spring集成自己有处理,详细看这里:讲解了三种方式


题主,我们又见面了....

请试试将properties改为如下:

<properties>
   <property name="filenameLog">${sys:catalina.base}/logs/payPlatform.log</property>
</properties>

请参考http://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution

【热门文章】
【热门文章】