使用 Logback SSLSocketAppender 时 Splunk 日志显示为十六进制

我正在尝试使用 Splunk 为我的应用收集日志。我在端口 6514 上设置了 TCP 数据输入(在此端口上启用了 SSL)。从我的 Java 应用程序中,我能够连接到端口并发送日志。但是,当我在 Splunk Web 上检查这些日志时,它显示为 Hex 格式。


回退配置


<configuration debug="true">


 <appender name="console" class="ch.qos.logback.core.ConsoleAppender">

    <encoder>

        <pattern>%date{ISO8601} [%thread] [%cyan(%C.%M\(\))] [%highlight(%level)] : %msg - %ex{short} %n</pattern>

    </encoder>

</appender>


<appender name="sslsocket" class="ch.qos.logback.classic.net.SSLSocketAppender">

    <remoteHost>127.0.0.1</remoteHost>

    <port>6514</port>

    <queueSize>20</queueSize>

    <reconnectionDelay>20</reconnectionDelay>

    <ssl>

        <trustStore>

            <location>file:///path/to/truststore.jks</location>

            <password>truststorepassword</password>

        </trustStore>

    </ssl>

</appender>


<logger name="splunk.secure.logger" additivity="false" level="INFO">

    <appender-ref ref="sslsocket"/>

</logger>


<root level="DEBUG">

    <appender-ref ref="console" />

</root>

</configuration>

用法


公共类启动器{


private final static org.slf4j.Logger logger = LoggerFactory.getLogger("splunk.secure.logger");



public static void main(String[] args) {

    logger.info("Testing SSL Socket Appender Log");

}


}

将调试输出记录回控制台


11:00:04,701 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - 

About to instantiate appender of type 

[ch.qos.logback.classic.net.SSLSocketAppender]

11:00:04,720 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - 

Naming appender as [sslsocket]

11:00:04,763 |-INFO in 

ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type 

[ch.qos.logback.core.net.ssl.SSLConfiguration] for [ssl] property

SPLUNK WEB 接收到的内容


Time    Event

19 年 3 月 2 日上午 9:48:45.000

\xAC\xED\x00 主机 = 127.0.0.1 源 = tcp:6514 源类型 = logback


总之


从上面看,在我看来这不是连接问题,因为 Splunk 正在侦听端口 6514 并且能够捕获输入但捕获的输入显示为 HEX 而不是正常情况。


当我使用普通的 com.splunk.logging.TcpAppender 时,我的日志会在 splunk 上正确显示。

  1. 有没有我可能错过的其他配置

  2. 使用 com.splunk.logging.TcpAppender 时是否可以启用 SSL

  3. 是否有专用的 Splunk SSL appender 可以用来代替 ch.qos.logback.classic.net.SSLSocketAppender

  4. 欢迎任何其他建议。


江户川乱折腾
浏览 199回答 1
1回答

小怪兽爱吃肉

为了解决这个问题,我不得不切换到 log4j。使用 log4j 中的以下配置,日志在 splunk web 上正确显示。<?xml version="1.0" encoding="UTF-8"?><Configuration status="info" name="example" packages=""><Appenders>&nbsp; &nbsp; <Socket name="ssl" host="localhost" port="6514">&nbsp; &nbsp; &nbsp; &nbsp; <PatternLayout charset="UTF-8">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <pattern>%date{ISO8601} [%thread] [%C.%M\(\) - Line %L] [%level] : %msg %ex{short} %n</pattern>&nbsp; &nbsp; &nbsp; &nbsp; </PatternLayout>&nbsp; &nbsp; &nbsp; &nbsp; <JsonLayout properties="true"/>&nbsp; &nbsp; &nbsp; &nbsp; <SSL>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TrustStore location="/path/to/keystore.jks" password="password"/>&nbsp; &nbsp; &nbsp; &nbsp; </SSL>&nbsp; &nbsp; </Socket>&nbsp; &nbsp; </Appenders>&nbsp; &nbsp; <Loggers>&nbsp; &nbsp; <Root level="INFO">&nbsp; &nbsp; </Root>&nbsp; &nbsp; <Logger name="splunk.secure.logger" level="info">&nbsp; &nbsp; &nbsp; &nbsp; <AppenderRef ref="ssl"/>&nbsp; &nbsp; </Logger>&nbsp; &nbsp; </Loggers></Configuration>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java