Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Mar 2, 2017
1 parent 32284f3 commit 4a4dc59
Showing 1 changed file with 6 additions and 41 deletions.
47 changes: 6 additions & 41 deletions src/main/java/com/dtstack/jlogstash/filters/BaseFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@
*/
package com.dtstack.jlogstash.filters;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dtstack.jlogstash.render.FreeMarkerRender;
import com.dtstack.jlogstash.render.TemplateRender;


/**
*
Expand All @@ -41,32 +35,13 @@
public abstract class BaseFilter implements Cloneable, java.io.Serializable{

private static final long serialVersionUID = -6525215605315577598L;

private static final Logger logger = LoggerFactory.getLogger(BaseFilter.class);

protected Map config;
protected List<TemplateRender> IF;
protected TemplateRender render;
protected String tagOnFailure;
protected ArrayList<String> removeFields;

public BaseFilter(Map config) {
this.config = config;

if (this.config.containsKey("if")) {
IF = new ArrayList<TemplateRender>();
for (String c : (List<String>) this.config.get("if")) {
try {
IF.add(new FreeMarkerRender(c, c));
} catch (IOException e) {
logger.error(e.getMessage());
System.exit(1);
}
}
} else {
IF = null;
}

if (config.containsKey("tagOnFailure")) {
this.tagOnFailure = (String) config.get("tagOnFailure");
} else {
Expand All @@ -78,29 +53,19 @@ public BaseFilter(Map config) {

public Map process(Map event) {
if(event != null && event.size() > 0){
boolean succuess = true;
if (this.IF != null) {
for (TemplateRender render : this.IF) {
if (!render.render(event).equals("true")) {
succuess = false;
break;
}
}
}
if (succuess == true) {
try{
event = this.filter(event);
this.postProcess(event,true);
}catch(Exception e){
this.postProcess(event,false);
}
try{
event = this.filter(event);
this.postProcess(event,true);
}catch(Exception e){
this.postProcess(event,false);
}
}
return event;
}

protected abstract Map filter(Map event) ;

@SuppressWarnings("unchecked")
public void postProcess(Map event, boolean ifsuccess) {
if (ifsuccess == false) {
if (this.tagOnFailure == null) {
Expand Down

0 comments on commit 4a4dc59

Please sign in to comment.