slf4j2elk

ELK(elasticsearch,logstash,kibana) client for Slf4j

License

License

Categories

Categories

SLF4J Application Layer Libs Logging
GroupId

GroupId

com.denghb
ArtifactId

ArtifactId

slf4j2elk
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

slf4j2elk
ELK(elasticsearch,logstash,kibana) client for Slf4j
Project URL

Project URL

https://github.com/deng-hb/slf4j2elk
Source Code Management

Source Code Management

https://github.com/deng-hb/slf4j2elk

Download slf4j2elk

How to add to project

<!-- https://jarcasting.com/artifacts/com.denghb/slf4j2elk/ -->
<dependency>
    <groupId>com.denghb</groupId>
    <artifactId>slf4j2elk</artifactId>
    <version>1.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.denghb/slf4j2elk/
implementation 'com.denghb:slf4j2elk:1.0.3'
// https://jarcasting.com/artifacts/com.denghb/slf4j2elk/
implementation ("com.denghb:slf4j2elk:1.0.3")
'com.denghb:slf4j2elk:jar:1.0.3'
<dependency org="com.denghb" name="slf4j2elk" rev="1.0.3">
  <artifact name="slf4j2elk" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.denghb', module='slf4j2elk', version='1.0.3')
)
libraryDependencies += "com.denghb" % "slf4j2elk" % "1.0.3"
[com.denghb/slf4j2elk "1.0.3"]

Dependencies

compile (1)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.25

Project Modules

There are no modules declared in this project.

slf4j2elk

demo版暂不能在生产中使用

基于slf4j-simple源码修改

Maven中使用在pom.xml

<dependency>
  <groupId>com.denghb</groupId>
  <artifactId>slf4j2elk</artifactId>
  <version>1.0.3</version>
</dependency>

项目classpath创建slf4j2elk.properties并写入一下内容

# 日志级别
com.denghb.slf4j2elk.level=DEBUG
# (可选)应用ID
com.denghb.slf4j2elk.id=10001
# (可选)ELK logstash 日志input http地址
com.denghb.slf4j2elk.server=http://localhost:31311
# (可选)本地写入日志文件目录
com.denghb.slf4j2elk.file=/tmp/slf4j2elk

ELK(elasticsearch、logstash、kibana) 服务安装运行

下载以下程序并解压运行 官网下载https://www.elastic.co/downloads打开很慢

  • [elasticsearch-5.2.2]
# 解压
unzip elasticsearch-5.2.2.zip
# 启动并后台运行
cd elasticsearch-5.2.2/bin
nohup ./elasticsearch &
# PS:不能以root用户运行

查看服务状态Elasticsearch http://localhost:9200

  • [logstash-5.2.2]
# 解压
unzip logstash-5.2.2.zip
cd logstash-5.2.2/bin/

# 创建配置文件并写入以下配置
vim logstash.conf 
input {
  http {
    host => "127.0.0.1"
    port => 31311
  }
}

filter {
  mutate {
     remove_field => ["headers"]
  }
}

output {
  elasticsearch { hosts => ["localhost:9200"] }
  stdout { codec => rubydebug }
}
# 启动并后台运行
nohup ./logstash -f logstash.conf &

# 查看日志
tail -100f nohup.out

测试发送日志

curl -H "Content-Type: application/json" -XPUT 'http://127.0.0.1:31311' -d '{"appId":"10001","level":"ERROR","content":"hello world"}'
  • [kibana-5.2.2]
# 解压
tar -zxvf kibana-5.2.2-darwin-x86_64.tar.gz
# 启动并后台运行
cd kibana-5.2.2-darwin-x86_64/bin
nohup ./kibana &

查看日志 http://localhost:5601

Versions

Version
1.0.3
1.0.2
1.0.1