简体   繁体   English

用于 Java 的 Elastic Search 自定义记录器

[英]Elastic Search custom logger for Java

Currently we have several Java micro service apps that use Elastic Search, and for debugging purposes we have the logging set to tracer.目前,我们有几个使用 Elastic Search 的 Java 微服务应用程序,出于调试目的,我们将日志记录设置为跟踪器。 This outputs all ES requests and responses to the logs.这会将所有 ES 请求和响应输出到日志。 We really only need requests, and only on non-production.我们真的只需要请求,并且只需要非生产。 For all environments we want to keep search response times along with a custom header that we set for tracking purposes across multiple micro service apps.对于所有环境,我们希望保留搜索响应时间以及我们为跨多个微服务应用程序进行跟踪而设置的自定义标头。

I see that in .NET there is a custom solution that would work perfectly for us: https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/logging-with-on-request-completed.html#logging-with-on-request-completed but sadly I can't seem to find a matching Java feature.我看到在 .NET 中有一个对我们来说非常适合的自定义解决方案: https : //www.elastic.co/guide/en/elasticsearch/client/net-api/current/logging-with-on-request- Completed.html#logging-with-on-request-completed但遗憾的是我似乎找不到匹配的 Java 功能。

Is there a way to do this using Java?有没有办法使用Java来做到这一点?

If I got you question correct then you want the following :-如果我的问题是正确的,那么您需要以下内容:-

  1. Log every elasticsearch query only (and not response) from different microservices.仅记录来自不同微服务的每个 elasticsearch 查询(而不是响应)。
  2. You just want it on your test clusters你只想要它在你的测试集群上

There is a workaround in elastisearch for the same.在 elastisearch 中有一个解决方法。 Elasticsearch itself logs the queries made to it and you just need to set a threshold for it. Elasticsearch 本身会记录对其进行的查询,您只需要为其设置一个阈值。 So any query that takes more time than that threshold would be logged in a separate file " _slow_log. " in your logs folder.因此,任何比该阈值花费更多时间的查询都将记录在日志文件夹中的单独文件“ _slow_log. ”中。 You just simply need to set the threshold to "0" to log every query only and agin this can be done in testing enviorments for your particular usecase.您只需将阈值设置为“0”即可仅记录每个查询,并且这可以在您的特定用例的测试环境中完成。

There are a lot of configuration options in it and would recommend you to check this : https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-slowlog.html其中有很多配置选项,建议您检查一下: https : //www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-slowlog.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM