@@ -50,6 +50,14 @@ See the [Java Pattern](https://docs.oracle.com/javase/8/docs/api/java/util/regex
50
50
)
51
51
Boolean hideOutput
52
52
53
+ @PluginProperty (
54
+ title = ' Capture multiple values' ,
55
+ description = ''' If true, each line is scanned separately to match the regex, capturing multiple key/value pairs.
56
+ If it just capture one group, each matched value will be added for the same key''' ,
57
+ defaultValue = ' false'
58
+ )
59
+ Boolean captureMultipleKeysValues
60
+
53
61
@PluginProperty (
54
62
title = ' Log Data' ,
55
63
description = ''' If true, log the captured data''' ,
@@ -87,7 +95,11 @@ See the [Java Pattern](https://docs.oracle.com/javase/8/docs/api/java/util/regex
87
95
@Override
88
96
void handleEvent (final PluginLoggingContext context , final LogEventControl event ) {
89
97
if (event. eventType == ' log' && event. loglevel == LogLevel . NORMAL && event. message?. length() > 0 ) {
90
- buffer. append(event. message). append(System . getProperty(" line.separator" ))
98
+ if (captureMultipleKeysValues){
99
+ extractKeyValue(event. message)
100
+ } else {
101
+ buffer. append(event. message). append(System . getProperty(" line.separator" ))
102
+ }
91
103
92
104
if (hideOutput){
93
105
event. loglevel = LogLevel . DEBUG
@@ -98,30 +110,12 @@ See the [Java Pattern](https://docs.oracle.com/javase/8/docs/api/java/util/regex
98
110
99
111
@Override
100
112
void complete (final PluginLoggingContext context ) {
101
-
102
113
if (buffer. size()> 0 ){
103
- Matcher match = dataPattern. matcher(buffer. toString())
104
-
105
- if (match. matches()) {
106
- def key,value
107
-
108
- if (match. groupCount()> 0 ){
109
- if (match. groupCount()== 1 && name){
110
- key = name
111
- value = match. group(1 )
112
- }else {
113
- if (match. groupCount()> 1 ){
114
- key = match. group(1 )
115
- value = match. group(2 )
116
- }
117
- }
114
+ extractKeyValue(buffer. toString())
115
+ }
118
116
119
- if (key && value) {
120
- allData[key] = value
121
- outputContext. addOutput(" data" , key, value)
122
- }
123
- }
124
- }
117
+ if (! allData. isEmpty()){
118
+ allData. each {outputContext. addOutput(" data" , it. getKey(), it. getValue())}
125
119
126
120
if (logData) {
127
121
context. log(
@@ -134,6 +128,33 @@ See the [Java Pattern](https://docs.oracle.com/javase/8/docs/api/java/util/regex
134
128
)
135
129
}
136
130
}
131
+ }
132
+
133
+ private void extractKeyValue (String output ){
134
+ Matcher match = dataPattern. matcher(output)
135
+
136
+ if (match. matches()) {
137
+ def key,value
138
+
139
+ if (match. groupCount()> 0 ){
140
+ if (match. groupCount()== 1 && name){
141
+ key = name
142
+ value = match. group(1 )
143
+ }else {
144
+ if (match. groupCount()> 1 ){
145
+ key = match. group(1 )
146
+ value = match. group(2 )
147
+ }
148
+ }
137
149
150
+ if (key && value) {
151
+ if (allData[key]) {
152
+ allData[key] + = " \n $value "
153
+ } else {
154
+ allData[key] = value
155
+ }
156
+ }
157
+ }
158
+ }
138
159
}
139
160
}
0 commit comments