How to use log4j with udp
I was able to successfully integrate log4j with a UDP server.
Here's what I did. I used log4j2. log4j-core-2,0-beta4.jar log4j-api-2.0-beta4.jar are two jar files.
The client sends logger.debug ("test message");
and the server will receive it like below.
import org.apache.logging.log4j.core.LogEvent;
LogEvent logEvent = null;
ObjectInputStream obj = null;
enter code here
bis = new ByteArrayInputStream(UDPpacket.getData());
obj = new ObjectInputStream(bis);
logEvent = (LogEvent) obj.readObject();
System.out.println("Got it : " + logEvent.toString());
System.out.println("Got Message : "+ logEvent.getMessage().getFormattedMessage());
source to share
To access the protocol over UDP to work in Log4j 1.2, we downloaded the source for UDPAppender from the now abandoned (?) "Apache Receivers Companion for log4j 1.2" project (to back up useful code from the abandoned Log4j 1.3 project) and compiled it ourselves. Initial tests show it works great, BUT I hope you noticed that I "threw" above twice ...
Project page: http://logging.apache.org/log4j/companions/receivers/index.html
Source code (NOT in the repo linked to the project page, they moved it to "extra"): http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org / apache / log4j / receivers / net /
source to share