项目简介
logstash4j 用于日志的输入、转换处理、输出, java 开发者自己的 logstash
特性
-
input
-
output
-
filter
-
metric
开源地址
快速开始
需要
jdk1.8+
maven 3.x+
maven 引入
<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}
yaml 例子
yaml 配置
- gen_test.yaml
---
outputs:
- StdOut: {}
inputs:
- StdIn: {}
filters:
- Add:
addField2: "value2"
addField1: "value1"
java 代码
ILogstashManageConfig config = new YamlLogstashManageConfig("gen_test.yaml");
LogstashManageCoreBs.newInstance()
.manageConfig(config)
.init()
.run();
效果和上面类似,只是换了一种配置方式。
ROAD-MAP
满足下面的话,可以让组件更加的强大。