Logback send logs using ssl

Viewed 58

I am trying to send logs via ssl to syslog-ng. The only appender I found in documentation that is capable of doing this is SSLSocketAppender. According to documentation the message is wrapped by LoggingEvent object.

SocketAppender is designed to log to a remote entity by transmitting serialized ILoggingEvent instances over the wire"

Now in syslog-ng I receive something like this:

Aug 26 14:50:33 10.230.91.71 ’
Aug 26 15:17:37 10.230.91.71 sr
Aug 26 15:17:37 10.230.91.71 )ch.qos.logback.classic.spi.LoggingEventVOZó€üě
Aug 26 15:17:37 10.230.91.71 H
Aug 26 15:17:37 10.230.91.71    J
Aug 26 15:17:37 10.230.91.71    timeStamp[
Aug 26 15:17:37 10.230.91.71 callerDataArrayt
......

How to make this work? I read that i can configure SSLServerSocketReceiver to receive messages. I assume that this receiver will be capable of deserializing messages properly and pass them forward to syslog but it would require to create an application only for doing that. Is there an easier way? I simply want to send logs to syslog using ssl.

1 Answers

I was also facing same issue, but instead of using SSLSocketAppender you can use logstash LogstashTcpSocketAppender to send logs to syslog-ng server.

  1. use below dependency in your pom.
   <dependency>
    <groupId>net.logstash.logback</groupId>
    <artifactId>logstash-logback-encoder</artifactId>
    <version>7.2</version>
</dependency>
  1. use LogstashTcpSocketAppender of logstash in your logback.xml as shown below file.
 <?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">

    <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>ip_address:port</destination>

        <!-- encoder is required -->

        <encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
        
        <ssl>
            <trustStore>
                <location>path of trust store</location>
                <password>your truststore password</password>
            </trustStore>
        </ssl>
    </appender>

    <root level="info">
     
        <appender-ref ref="stash"/>
    </root>
    <logger name="org.springframework" level="info"/>
</configuration>

For more info please visit : https://github.com/logfellow/logstash-logback-encoder#ssl

Related