[英]How to index logs from java program (log4j2) into elasticsearch
How can I index logs directly from log4j2 into elasticsearch index? 如何将日志直接从log4j2索引到elasticsearch索引中?
Main.class: Main.class:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Main {
private static final Logger logger = LogManager.getLogger(Main.class);
public static void main(String... args) {
logger.info("This is an info message.");
logger.error("This is an error message");
}
}
log4j2.xml: log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="STDOUT" level="trace"/>
</Root>
</Loggers>
</Configuration>
I want to know if there is a way to inject logs directly into elasticsearch, by adding dependency and appenders to logger. 我想知道是否存在一种通过将依赖项和附加器添加到logger来将日志直接注入elasticsearch的方法。
You can use my plugin: https://github.com/rfoltyns/log4j2-elasticsearch . 您可以使用我的插件: https : //github.com/rfoltyns/log4j2-elasticsearch 。 It does exactly what you need.
它完全满足您的需求。
Be sure to configure the IndexTemplate
and use log4j2-*:(,2.10] to avoid https://github.com/rfoltyns/log4j2-elasticsearch/issues/9 . I'll release a fix for that soon. 请确保配置
IndexTemplate
并使用log4j2-* :(,2.10]以避免https://github.com/rfoltyns/log4j2-elasticsearch/issues/9 ,我将尽快发布修复程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.