-
Notifications
You must be signed in to change notification settings - Fork 4
/
logback-dingtalk-robot-pattern-layout.xml
52 lines (51 loc) · 3.33 KB
/
logback-dingtalk-robot-pattern-layout.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?xml version="1.0" encoding="UTF-8"?>
<included>
<if condition='property("dingTalkRobotWebhook").length()>0 && property("dingTalkRobotTitle").length()>0'>
<!-- http://logback.qos.ch/manual/configuration.html#conditional-->
<!-- The condition is a Java expression in which only context properties or system properties are accessible.
For a key passed as argument, the property() or its shorter equivalent p() methods return the String value of the property.
For example, to access the value of a property with key "k", you would write property("k") or equivalently p("k").
If the property with key "k" is undefined, the property method will return the empty string and not null.
This avoids the need to check for null values.-->
<then>
<!-- 通过logback PatternLayoutEncoder 定义 markdown 格式-->
<appender name="dingtalkPatternLayoutEncoderAppend"
class="com.github.wangji92.dingtalkrobot.logback.append.DingTalkRobotAppend">
<webhook>${dingTalkRobotWebhook}</webhook>
<signSecret>${dingTalkRobotSignSecret}</signSecret>
<robotTitle>${dingTalkRobotTitle}</robotTitle>
<!-- 不要随便格式化 很危险-->
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${DINGTALK_ROBOT_LOG_PATTERN}</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!--自定义layout的效果+ AsyncAppender-->
<appender name="asyncDingtalkPatternLayoutEncoderAppend" class="ch.qos.logback.classic.AsyncAppender">
<includeCallerData>${asyncAppenderIncludeCallerData:-true}</includeCallerData>
<queueSize>${asyncAppenderQueueSize:-256}</queueSize>
<neverBlock>${asyncAppenderNeverBlock:-true}</neverBlock>
<appender-ref ref="dingtalkPatternLayoutEncoderAppend"/>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>${dingTalkLogLevel:-ERROR}</level>
</filter>
<!-- 可以通过表达式过滤 [eg 关键字]-->
<!-- http://logback.qos.ch/manual/filters.html#EvaluatorFilter-->
<!-- return formattedMessage.contains("dingtalk") || formattedMessage.contains("xxxKeWord");-->
<if condition='property("dingTalkLogConfigKewWordExpression").length()>0'>
<then>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
<expression>${dingTalkLogConfigKewWordExpression}</expression>
</evaluator>
<!-- 用于配置符合过滤条件的操作 -->
<onMatch>ACCEPT</onMatch>
<!-- 用于配置不符合过滤条件的操作 -->
<onMismatch>DENY</onMismatch>
</filter>
</then>
</if>
</appender>
</then>
</if>
</included>