-
Notifications
You must be signed in to change notification settings - Fork 4
/
logback-dingtalk-robot-custom-layout.xml
54 lines (53 loc) · 3.46 KB
/
logback-dingtalk-robot-custom-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
53
54
<?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>
<!--自定义layout的效果-->
<appender name="dingTalkCustomLayoutAppend"
class="com.github.wangji92.dingtalkrobot.logback.append.DingTalkRobotAppend">
<webhook>${dingTalkRobotWebhook}</webhook>
<signSecret>${dingTalkRobotSignSecret}</signSecret>
<robotTitle>${dingTalkRobotTitle}</robotTitle>
<rateLimiterPermitsPerSecond>${dingTalkRateLimiterPermitsPerSecond:-0.2875}</rateLimiterPermitsPerSecond>
<layout class="com.github.wangji92.dingtalkrobot.logback.layout.DingTalkRobotLayout">
<env>${env}</env>
<app>${app}</app>
<clickDescription>${dingTalkQuickLinkClickDescription}</clickDescription>
<clickUrl>${dingTalkQuickLinkClickUrl}</clickUrl>
</layout>
</appender>
<!--自定义layout的效果+ AsyncAppender-->
<appender name="asyncDingTalkCustomLayoutAppend" class="ch.qos.logback.classic.AsyncAppender">
<includeCallerData>${asyncAppenderIncludeCallerData:-true}</includeCallerData>
<queueSize>${asyncAppenderQueueSize:-256}</queueSize>
<neverBlock>${asyncAppenderNeverBlock:-true}</neverBlock>
<appender-ref ref="dingTalkCustomLayoutAppend"/>
<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>