From 57c6280c7e084dd8512d099ae738d4fbb1baf343 Mon Sep 17 00:00:00 2001 From: Maxime Chassagneux <4163013@airfrance.fr> Date: Wed, 18 Jan 2017 13:01:53 +0100 Subject: [PATCH] Allow multiples fields ( end with _value ) --- .../com/airfrance/diqmqs/logparser/Parser.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/airfrance/diqmqs/logparser/Parser.java b/src/main/java/com/airfrance/diqmqs/logparser/Parser.java index 02f47a4..b907549 100644 --- a/src/main/java/com/airfrance/diqmqs/logparser/Parser.java +++ b/src/main/java/com/airfrance/diqmqs/logparser/Parser.java @@ -25,7 +25,7 @@ public class Parser extends TailerListenerAdapter { private String metricLine = ""; String tagName = null; String tagValue = null; - String value = null; + String field = null; private Log log = Log.getLogger(Parser.class.getName()); private Random randomGenerator = new Random(); @@ -64,7 +64,7 @@ public class Parser extends TailerListenerAdapter { sb.append(metricLine); tagName = null; tagValue = null; - value = null; + field = ""; // iterate on all match pattern boolean hasDate = false; @@ -76,9 +76,12 @@ public class Parser extends TailerListenerAdapter { if ( StringUtils.isAllLowerCase( tagName ) ) { tagValue = entry.getValue().toString(); - // if key name is 'value', it's not a tag, but a field - if ( tagName.equalsIgnoreCase("value") ) { - value = tagValue; + // if key name end with '_value', it's not a tag, but a field ! + if ( tagName.endsWith("_value") ) { + // check if tag value is not empty + if (!tagValue.equalsIgnoreCase("") ) { + field += sanitizeString(tagName.replaceAll("_value", "")) + "=" + sanitizeString(tagValue) + " "; + } } else { @@ -131,9 +134,8 @@ public class Parser extends TailerListenerAdapter { } sb.append(" "); //Field - if ( StringUtils.isNumeric(value) ) { - sb.append("value=") - .append(value); + if ( !field.isEmpty() ) { + sb.append(field); } else {