Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SocketAppender and PatternLayout

I have a logger that send log to a log server storage. This work fine but the patternlayout isn't used. With or without that doesn't change anything. I believe remember to read somewhere that socketappender use is own pattern and not others.

<appender name="LOGSTASH" class="org.apache.log4j.net.SocketAppender"> 
        <param name="Port" value="5000"/>
        <param name="RemoteHost" value="192.168.81.131"/> 
        <param name="ReconnectionDelay" value="5000"/>
        <param name="LocationInfo" value="true" />
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n" />
      </layout>
</appender> 

But on this documentation (and a few other) thay use this. Example from this doc :

<appender name="A1" class="org.apache.log4j.net.SocketAppender">
    <param name="RemoteHost" value="localhost"/>
    <param name="Port" value="5000"/>
    <param name="LocationInfo" value="true"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/>
    </layout>
    </appender>

So is it impossible to use personnal pattern with socketappender or is it my fault?

If it's impossible is there an alternative appender for tcp logging with custom pattern?

like image 876
Guinoutortue Avatar asked Nov 01 '22 13:11

Guinoutortue


1 Answers

It seems that SocketAppender don't use a layout.

SocketAppenders do not use a layout. They ship a serialized LoggingEvent object to the server side.

See documentation here


So I use a SyslogAppender to replace. It's not perfect because of unused possibilies (like facility and priority) but works fine.

like image 87
Guinoutortue Avatar answered Nov 08 '22 14:11

Guinoutortue