我想通过 Http 将所有日志发送到另一个服务。我不想为此编写自定义网络客户端。是否有任何日志库可以将日志发布到Web服务?在 .net 方面,我可以使用 Serilog sink seq 来完成此操作。 Spring中有没有像Serilog这样的库?
最佳答案
Log4J 有多个 Appender,其中之一是 HTTP Appender。
https://logging.apache.org/log4j/2.x/manual/appenders.html#HttpAppender
请参阅下面的要求和示例:
HttpAppender
The HttpAppender sends log events over HTTP. A Layout must be provided to format the LogEvent.
Will set the Content-Type header according to the layout. Additional headers can be specified with embedded Property elements.
Will wait for response from server, and throw error if no 2xx response is received.
Here is a sample HttpAppender configuration snippet:
<?xml version="1.0" encoding="UTF-8"?>
<Appenders>
<Http name="Http" url="https://localhost:9200/test/log4j/">
<Property name="X-Java-Runtime" value="$${java:runtime}" />
<JsonLayout properties="true"/>
<SSL>
<KeyStore location="log4j2-keystore.jks" passwordEnvironmentVariable="KEYSTORE_PASSWORD"/>
<TrustStore location="truststore.jks" passwordFile="${sys:user.home}/truststore.pwd"/>
</SSL>
</Http>
</Appenders>
</xml>
关于java - 在 Spring 中将日志发送到另一个服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67871549/