Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4J Appender UDP

Tags:

sockets

log4j

udp

I need to use log4j to append logs to a socket with UDP. However, I cannot find much on the internet about how to do so. In Log4J, the socketappender uses TCP. So I got log4j 2 beta, but I can't find any examples/documentation on how to use the socketappender, especially for UDP. I would really appreciate it if anyone could give me an example/show me how to use Log4j for UDP. Thanks.

like image 737
user1440061 Avatar asked Nov 19 '25 17:11

user1440061


1 Answers

I have been working with log4j 2.0-beta8 and got the UDP appender working with following log4j2.xml file (but note the 2 in the name of the file!):

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <appenders> 
          <Socket name="UDP" host="myhostname.com" port="3333" protocol="UDP">
        <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1} - %m%n"/>
       </Socket>
       </appenders>
       <loggers>
           <root level="info">
               <appender-ref ref="UDP"/>
           </root>
       </loggers>
    </configuration>
like image 105
C R Avatar answered Nov 21 '25 06:11

C R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!