logstash4j 用于日志的输入、转换处理、输出, java 开发者自己的 logstash
input
output
filter
metric
jdk1.8+
maven 3.x+
<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>logstash4j-core</artifactId>
<version>0.9.0</version>
</dependency>
import com.github.houbb.logstash4j.core.api.ILogstashConfigClassName;
import com.github.houbb.logstash4j.core.api.ILogstashManageConfig;
import com.github.houbb.logstash4j.core.bs.LogstashManageCoreBs;
import com.github.houbb.logstash4j.core.support.config.LogstashConfigClassName;
import java.util.*;
public class LogstashManageCoreBsTest {
public static void main(String[] args) {
ILogstashManageConfig config = new ILogstashManageConfig() {
@Override
public List<ILogstashConfigClassName> getInputConfigList() {
List<ILogstashConfigClassName> list = new ArrayList<>();
LogstashConfigClassName logstashConfigClassName = new LogstashConfigClassName(new HashMap<String, Object>());
logstashConfigClassName.setClassName("com.github.houbb.logstash4j.plugins.input.StdIn");
list.add(logstashConfigClassName);
return list;
}
@Override
public List<ILogstashConfigClassName> getFilterConfigList() {
//1. add
List<ILogstashConfigClassName> list = new ArrayList<>();
Map<String, Object> configMap = new HashMap<>();
configMap.put("addField1", "value1");
configMap.put("addField2", "value2");
LogstashConfigClassName logstashConfigClassName = new LogstashConfigClassName(configMap);
logstashConfigClassName.setClassName("com.github.houbb.logstash4j.plugins.filter.Add");
list.add(logstashConfigClassName);
return list;
}
@Override
public List<ILogstashConfigClassName> getOutConfigList() {
List<ILogstashConfigClassName> list = new ArrayList<>();
LogstashConfigClassName logstashConfigClassName = new LogstashConfigClassName(new HashMap<String, Object>());
logstashConfigClassName.setClassName("com.github.houbb.logstash4j.plugins.output.StdOut");
list.add(logstashConfigClassName);
return list;
}
};
//run
LogstashManageCoreBs.newInstance()
.manageConfig(config)
.init()
.run();
}
}
11111111111
Stdout: {addField2=value2, addField1=value1, message=11111111111}
3333333333333333
Stdout: {addField2=value2, addField1=value1, message=3333333333333333}
---
outputs:
- StdOut: {}
inputs:
- StdIn: {}
filters:
- Add:
addField2: "value2"
addField1: "value1"
ILogstashManageConfig config = new YamlLogstashManageConfig("gen_test.yaml");
LogstashManageCoreBs.newInstance()
.manageConfig(config)
.init()
.run();
效果和上面类似,只是换了一种配置方式。
满足下面的话,可以让组件更加的强大。