Warm tip: This article is reproduced from serverfault.com, please click

java-从Spring应用单独登录到Elastic Stack

(java - Logging separately from Spring app into Elastic stack)

发布于 2020-11-28 11:58:18

我有一个Spring Boot应用程序和一个Elastic堆栈(Elasticsearch + Kibana + Filebeat,没有Logstash)。每当有请求发送到我的Spring应用程序时,我都希望记录一些信息(例如,请求URL和请求用户ID)。

第一种幼稚的方法是简单地记录该(log.info("request comes url={} user={}", url, user);)。然后,filebeat将很高兴将其收集到我的elasticsearch中,并且我可以使用Kibana对其进行可视化。

但是,我不希望这些数据与索引模式中的所有其他日志混合在一起filebeat-*我希望它们成为索引模式中的其他普通日志数据request-info(或request-info-*filebeat-*有什么办法吗?非常感谢你!

Questioner
ch271828n
Viewed
11
leandrojmp 2020-11-29 03:20:01

你可以filebeat.yml基于消息中存在的字符串在你的条件输出中使用

就像是:

output.elasticsearch:
  hosts: ["http://localhost:9200"]
  indices:
    - index: "request-info-%{+yyyy.MM.dd}"
      when.contains:
        message: "request comes"

例如,如果你的消息包含字符串request comes,则将其发送到索引request-info-2020.11.28,如果不包含该字符串,则将其发送到默认索引。

你可以elasticsearch output在此文档链接中了解有关选项的更多信息