项目简介

用于日志的输入、转换处理、输出, java 开发者自己的 logstash

特性

  • input
  • output
  • filter
  • metric

开源地址

logstash4j

快速开始

需要

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

满足下面的话,可以让组件更加的强大。

  • [ ] 如何可以让不同的 event 进行关联?
  • [ ] 如何让 input/filter/ouput 之间也可以关联?

日志矩阵

日志采集-logcollect-go

日志处理-logstash4j

日志处理插件-logstash4j-plugins

日志整合框架-log-integration

切面日志-auto-log

日志脱敏-sensitive

日志的全链路

全链路 auto-trace

唯一的跟踪号-trace-id

[包内链路信息]()

[应用间链路]()

日志检索

分词-segment

拼音-pinyin

中文繁简体转换-opencc4j

[日志存储+检索 类似ES:TODO]()

[日志的可视化 类似kibana:TODO]()

[日志分析-错误+慢日志+报警平台:TODO]()


老马啸西风
191 声望34 粉丝