log4j日志打印配置

文件名:log4j2.xml


<configuration monitorInterval="5">
    

    
    <Properties>
        <property name="LOG_PATTERN" value="[%date{yyyy/MM/dd HH:mm:ss.SSS}] [%thread:%c{1}:%L] %-5level  - %msg%n"/>
        
        <property name="FILE_PATH" value="./logs"/>
        <property name="FILE_NAME" value="fileName日志文件名"/>
    Properties>

    <appenders>

        
        <console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="${LOG_PATTERN}"/>
            
            
        console>

        
        <RollingFile name="RollingFileInfo" fileName="${FILE_PATH}/${FILE_NAME}.log"
                     filePattern="${FILE_PATH}/${FILE_NAME}.log.%d{yyyy-MM-dd}">
            
            <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="${LOG_PATTERN}"/>
            <Policies>
                
                <TimeBasedTriggeringPolicy interval="1"/>
            Policies>
        RollingFile>

        
        <RollingFile name="RollingFileError" fileName="${FILE_PATH}/error.log"
                     filePattern="${FILE_PATH}/error.log.%d{yyyy-MM-dd}">
            <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="${LOG_PATTERN}"/>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"/>
            Policies>
        RollingFile>

    appenders>

    <loggers>
        
        
        <Logger name="org.springframework" level="info" additivity="false">
            <AppenderRef ref="Console"/>
        Logger>

        <root level="info">
        	
            <appender-ref ref="Console"/>
            <appender-ref ref="RollingFileInfo"/>
            <appender-ref ref="RollingFileError"/>
        root>
    loggers>
configuration>


<configuration status="INFO">
    
    <Properties>
        <Property name="pattern" value="[%date{yyyy/MM/dd HH:mm:ss.SSS}] [%thread] %-5level  - %msg%n"/>

        
        <Property name="serviceName" value="serviceName"/>
        <property name="errorName" value="error" />
        <property name="path" value="./logs/" />
    Properties>
    <Appenders>
        <Console name="console" target="SYSTEM_OUT" follow="true">
            <PatternLayout>
            	
                <pattern>${pattern}pattern>
            PatternLayout>
        Console>

        <RollingFile name="errorFile" fileName="${path}/${errorName}.log" filePattern="${path}/${errorName}.log.%d{yyyy-MM-dd}">
            <ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="${pattern}" />
            <Policies>
                
                <TimeBasedTriggeringPolicy modulate="true" interval="1"/>
            Policies>
        RollingFile>


        <RollingFile name="infoFile" fileName="${path}/${serviceName}.log" filePattern="${path}/${serviceName}.log.%d{yyyy-MM-dd}">
            <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="${pattern}" />
            <Policies>
                <TimeBasedTriggeringPolicy modulate="true" interval="1"/>
            Policies>

        RollingFile>
    Appenders>


    <Loggers>
        <Logger name="org.springframework" level="INFO" />
        <Root level="INFO">
        	
            <AppenderRef ref="console">AppenderRef>
            <AppenderRef ref="infoFile">AppenderRef>
            <AppenderRef ref="errorFile">AppenderRef>
        Root>
    Loggers>

configuration>

你可能感兴趣的:(java,log4j)