美文网首页
日志[spring-boot-starter-log4j2]

日志[spring-boot-starter-log4j2]

作者: Sina华 | 来源:发表于2020-04-11 21:08 被阅读0次

    log4j2.xml 文件配置

    <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="WARN">
    <properties>

    <property name="LOG_HOME">./logs/@artifactId@/</property>
    <property name="FILE_NAME">@artifactId@</property>
    </properties>
    <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
    <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p - %m %l%n"/>
    </Console>

    <RollingRandomAccessFile name="sysFile" fileName="{LOG_HOME}/{FILE_NAME}-system.log"
    filePattern="{LOG_HOME}/{FILE_NAME}-system-%d{yyyy-MM-dd}-%i.log">
    <PatternLayout>
    <pattern>%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p - %m %l%n</pattern>
    </PatternLayout>
    <Policies>
    <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
    <SizeBasedTriggeringPolicy size="20MB"/>
    <DefaultRolloverStrategy max="20"/>
    </Policies>
    </RollingRandomAccessFile>

    <RollingRandomAccessFile name="controllerLogFile" fileName="{LOG_HOME}/{FILE_NAME}-controller.log"
    filePattern="{LOG_HOME}/{FILE_NAME}-controller-%d{yyyy-MM-dd}-%i.log">
    <PatternLayout>
    <pattern>%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p - %m %l%n</pattern>
    </PatternLayout>
    <Policies>
    <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
    <SizeBasedTriggeringPolicy size="20MB"/>
    <DefaultRolloverStrategy max="20"/>
    </Policies>
    </RollingRandomAccessFile>

    <RollingRandomAccessFile name="serviceLogFile" fileName="{LOG_HOME}/{FILE_NAME}-service.log"
    filePattern="{LOG_HOME}/{FILE_NAME}-service-%d{yyyy-MM-dd}-%i.log">
    <PatternLayout>
    <pattern>%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p - %m %l%n</pattern>
    </PatternLayout>
    <Policies>
    <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
    <SizeBasedTriggeringPolicy size="20MB"/>
    <DefaultRolloverStrategy max="20"/>
    </Policies>
    </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
    <Root level="info">
    <AppenderRef ref="Console"/>
    <AppenderRef ref="sysFile"/>
    </Root>

    <Logger name="com.trjcn.common.base.interceptor.ControllerLogAspect" level="info" additivity="false">
    <AppenderRef ref="controllerLogFile"/>
    <AppenderRef ref="Console"/>
    </Logger>

    <Logger name="com.trjcn.common.base.exception.CommonExceptionHandler" level="info" additivity="false">
    <AppenderRef ref="controllerLogFile"/>
    <AppenderRef ref="serviceLogFile"/>
    <AppenderRef ref="Console"/>
    </Logger>

    <Logger name="com.trjcn..controller" level="info" additivity="false">
    <AppenderRef ref="controllerLogFile"/>
    <AppenderRef ref="Console"/>
    </Logger>

    <Logger name="com.trjcn.
    .service.impl" level="info" additivity="false">
    <AppenderRef ref="serviceLogFile"/>
    <AppenderRef ref="Console"/>
    </Logger>
    </Loggers>
    </Configuration>

    相关文章

      网友评论

          本文标题:日志[spring-boot-starter-log4j2]

          本文链接:https://www.haomeiwen.com/subject/ccepmhtx.html