springboot 多日志

  1 <?xml version='1.0' encoding='UTF-8'?>
  2 <configuration>
  3     <springProperty name="logFile" source="log.file"/>
  4     <springProperty name="DataFileNettyUdp" source="data.txt"/>
  5     <springProperty name="rootlevel" source="log.level.root"/>
  6     <springProperty name="mylevel" source="log.level.my"/>
  7     <springProperty name="maxFileSize" source="log.maxsize"/>
  8     <springProperty name="maxDataFileSize" source="log.maxdatasize"/>
  9 
 10     <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
 11         <encoder>
 12             <pattern>{faint} %d [%thread] %-5level %logger{50} -[%file:%line]- %msg%n
 13             </pattern>
 14             <charset>UTF-8</charset>
 15         </encoder>
 16     </appender>
 17 
 18     <appender name="adminLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
 19         <file>${logFile}</file>
 20         <encoder>
 21             <pattern>%d [%thread] %-5level -[%file:%line]- %msg%n</pattern>
 22             <charset>UTF-8</charset>
 23         </encoder>
 24         <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
 25             <fileNamePattern>${logFile}.%d{yyyy-MM-dd}.%i</fileNamePattern>
 26             <maxFileSize>${maxFileSize}</maxFileSize>
 27         </rollingPolicy>
 28     </appender>
 29 
 30     <appender name="errorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
 31         <file>${logFile}.error</file>
 32         <encoder>
 33             <pattern>%d [%thread] %-5level %logger{36} -[%file:%line]- %msg%n
 34             </pattern>
 35             <charset>UTF-8</charset>
 36         </encoder>
 37         <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
 38             <fileNamePattern>${logFile}.error.%d{yyyy-MM-dd}.%i</fileNamePattern>
 39             <maxFileSize>${maxFileSize}</maxFileSize>
 40         </rollingPolicy>
 41         <filter class="ch.qos.logback.classic.filter.LevelFilter">
 42             <level>error</level>
 43             <onMatch>ACCEPT</onMatch>
 44             <onMismatch>DENY</onMismatch>
 45         </filter>
 46     </appender>
 47 
 48     <appender name="sqlLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
 49         <file>${logFile}.sql</file>
 50         <encoder>
 51             <pattern>%d [%thread] %msg%n
 52             </pattern>
 53             <charset>UTF-8</charset>
 54         </encoder>
 55         <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
 56             <fileNamePattern>${logFile}.sql.%d{yyyy-MM-dd}.%i</fileNamePattern>
 57             <maxFileSize>${maxFileSize}</maxFileSize>
 58         </rollingPolicy>
 59     </appender>
 60     <appender name="DataUse" class="ch.qos.logback.core.rolling.RollingFileAppender">
 61         <file>logs/mydata.txt</file>
 62         <append>true</append>
 63         <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
 64             <fileNamePattern>logs/data/%d{yyyy-MM-dd}/%d{HH}/data-%d{HH_mm}-%i.txt</fileNamePattern>
 65 <!--            <TimeBasedTriggeringPolicy interval="2" modulate ="true"/>-->
 66             <maxFileSize>500KB</maxFileSize>
 67             <maxHistory>30</maxHistory>
 68 <!--            <cleanHistoryOnStart>true</cleanHistoryOnStart>-->
 69         </rollingPolicy>
 70         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
 71             <pattern>%msg%n</pattern>
 72             <charset>UTF-8</charset>
 73         </encoder>
 74     </appender>
 75     <appender name="DataUdpUse" class="ch.qos.logback.core.rolling.RollingFileAppender">
 76         <file>logs/mydataudp.txt</file>
 77         <append>true</append>
 78         <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
 79             <fileNamePattern>logs/data/%d{yyyy-MM-dd}/%d{HH}/dataudp-%d{HH_mm}-%i.txt</fileNamePattern>
 80             <!--            <TimeBasedTriggeringPolicy interval="2" modulate ="true"/>-->
 81             <maxFileSize>500KB</maxFileSize>
 82             <maxHistory>30</maxHistory>
 83             <!--            <cleanHistoryOnStart>true</cleanHistoryOnStart>-->
 84         </rollingPolicy>
 85         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
 86             <pattern>%msg%n</pattern>
 87             <charset>UTF-8</charset>
 88         </encoder>
 89     </appender>
 90 
 91 <!--    <appender name="JasonLog" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
 92 
 93 <!--    </appender>-->
 94     <!--    指定包名/类,日志级别   -->
 95 <!--
 96 为何root配置的INFO,logger特殊指定的包/类日志DEBUG级别,最后也能打印出来
 97 因为没有设置addtivity="false" ,如下图即可。
 98 logger有一个配置addtivity="true" 默认就是true,标识向上级传递日志(INFO是DEBUG的上级)。只有显示指定为false时,才不会向上级输出。
 99 -->
100     <logger name="adminLogger" level="${mylevel}" additivity="true">
101         <appender-ref ref="adminLog"/>
102     </logger>
103 
104     <logger name="com.topwulian.dao" level="error" additivity="true">
105         <appender-ref ref="sqlLog"/>
106     </logger>
107     <logger name="DataLogger" level="info" additivity="true">
108         <appender-ref ref="DataUse"/>
109     </logger>
110     <logger name="DataUdpLogger" level="info" additivity="true">
111         <appender-ref ref="DataUdpUse"/>
112     </logger>
113     <!-- 彩色日志 -->
114     <!-- 彩色日志依赖的渲染类 -->
115     <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
116     <conversionRule conversionWord="wex"
117                     converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
118     <conversionRule conversionWord="wEx"
119                     converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
120     <!-- 彩色日志格式 -->
121     <property name="CONSOLE_LOG_PATTERN"
122               value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
123     <!-- Console 输出设置 -->
124     <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
125         <encoder>
126             <pattern>${CONSOLE_LOG_PATTERN}</pattern>
127             <charset>utf8</charset>
128         </encoder>
129     </appender>
130     <root level="${rootlevel}">
131         <appender-ref ref="CONSOLE"/>
132         <appender-ref ref="errorLog"/>
133     </root>
134 
135 
136 </configuration>

 

posted @ 2020-08-18 12:25  2eggs  Views(303)  Comments(0Edit  收藏  举报