You don't need to write a program for PC2 - any app that loads a log4j configuration file will do - as long as that configuration file contains both the receivers and appenders you need.
This means you can start SimpleSocketServer on PC2 configured with a log4j configuration file which contains two receiver entries and one appender entry. The receivers will start receiving the events once configuration is complete - the appender will append any events received by the receivers. Here's an example log4j config file you could use with the SimpleSocketServer (I know SimpleSocketServer has built-in support for listening on a socket - same as SocketReceiver, you could use that if you want instead of adding the socketreceiver section below - otherwise, make sure that's using a different port!): <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration > <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true"> <appender name="FILE" class="org.apache.log4j.FileAppender"> <param name="Append" value="false"/> <param name="File" value="log.txt"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/> </layout> </appender> <plugin name="SocketReceiver" class="org.apache.log4j.net.SocketReceiver"> <param name="Port" value="7776"/> </plugin> <plugin name="XMLSocketReceiver" class="org.apache.log4j.net.XMLSocketReceiver"> <param name="Port" value="7777"/> </plugin> <root> <level value="DEBUG"/> <appender-ref ref="FILE"/> </root> </log4j:configuration> Hope this helps Scott -----Original Message----- From: Wilfong, Paul [mailto:[EMAIL PROTECTED] Sent: Monday, August 13, 2007 8:30 AM To: Log4J Users List Subject: RE: Where is XMLSocketAppender for XMLSocketReceiver? Thanks very much for the reply! But I feel I am being dense about this. I have a PC, call it PC1, running a Java program using SocketAppender with port 7776. At the same time, PC1 is also running a C++ program using an XMLSocketAppender with port 7777. Now I have a second PC, call it PC2. I am looking at your reply to Claudia from long ago: "While you would have two receivers in your config file, it should work (all of the received events - from either receiver - will be handed over to the RollingFileAppender.)" This is exactly what I would like to do, but I don't know what you mean by "two receivers in your config file". Don't I need to write a program for PC2, analogous to the SocketServer program, that listens to 7776 for the PC1 Java program, and 7777 for the PC1 C++ program with XML, and uses a config file with the RollingFileAppender specified? The "two receivers in your config file" is what throws me. Does it mean there might be a way to set up PC2 without having to write a new SocketServer-like program? If so, that would be really great. Thanks for any help. -----Original Message----- From: Scott Deboy [mailto:[EMAIL PROTECTED] Sent: Thursday, August 09, 2007 5:16 PM To: Log4J Users List Subject: RE: Where is XMLSocketAppender for XMLSocketReceiver? XMLSocketReceiver was written to allow other frameworks (log4cxx, log4php, log4perl, java.util.logging) to send events to log4j over TCP - we already had that ability with SocketAppender/SocketReceiver, so we didn't see a need to write XMLSocketAppender. Scott Deboy -----Original Message----- From: Wilfong, Paul [mailto:[EMAIL PROTECTED] Sent: Thursday, August 09, 2007 2:27 PM To: [email protected] Subject: RE: Where is XMLSocketAppender for XMLSocketReceiver? I was wondering if this forum post was ever resolved. If so, would it be possible for the final config files to be posted? If not, could an overview of the difficulties be provided? The original issue was to have both Java and C programs logging, using log4j and log4cxx respectively. The Java program would use SocketAppender, and the C program XMLSocketAppender. Then, on another machine, SocketReceiver and XMLSocketReceiver would be used, both with RollingFileAppender. If I have this right, would a Java program need to be written to execute the SocketReceiver and XMLSocketReceiver logic? Thanks for any help. ______________________________________________________________________________________________________ Hi Claudia, I'd suggest using SocketAppender and adding a second receiver to your config file (SocketReceiver). While you would have two receivers in your config file, it should work (all of the received events - from either receiver - will be handed over to the RollingFileAppender.) Scott -----Original Message----- From: Clᵤia Miazaki [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 30, 2004 6:06 AM To: 'Log4J Users List' Cc: [EMAIL PROTECTED] Subject: Where is XMLSocketAppender for XMLSocketReceiver? Hi, I have tried Scott's suggestion and the combination of log4cxx's XMLSocketAppender sending logging events to log4j's XMLSocketReceiver did work but I wonder which appenders should be used if I wanted to log from log4j itself to a XMLSocketReceiver: I could not find XMLSocketAppender defined in log4j-1.3alpha. The issue is that I wanted to use the same XML configuration file for both C++ and Java apps, all of them sending logging events to the same XMLSocketReceiver, who will later use a RollingFileAppender. Regards, Claudia -----Mensagem original----- De: Clᵤia Miazaki [mailto:[EMAIL PROTECTED] Enviada em: sexta-feira, 25 de junho de 2004 15:29 Para: 'Scott Deboy'; 'Log4J Users List' Cc: [EMAIL PROTECTED] Assunto: RES: Log4j SocketServer with Log4cxx SockeAppender Hi, Sorry to bother again, but I am a newbie to all this logging and XML as well. I must be missing something (or maybe many things) because I can't make it work yet. Now I am using log4j v1.3-alpha from CVS and I did this sequence: (Step 1) Activation of log4j's SimpleSocketServer with this command: java org.apache.log4j.net.SimpleSocketServer 12345 siaclog_server.xml where file "siaclog_server.xml" is attached bellow and port 12345 is not being used in my machine. The last messages shown at this point inform: INFO - Listening on port 12345 INFO - Listening on port 12345 INFO - Waiting to accept a new client INFO - Waiting to accept a new client and then it "hangs" waiting for incoming logging events. (Step 2) Start-up the C++ application linked to log4cxx.dll (version 0.9.7). This application parses an XML configuration file called "siaclog_client.xml" (also attached) using DOMConfigurator. At this point these errors occur at the SimpleSocketServer: ERROR - Exception opening ObjectInputStream to Socket[addr=/127.0.0.1,port=4845,localport=12345] java.io.StreamCorruptedException: invalid stream header at java.io.ObjectInputStream.readStreamHeader(Unknown Source) ... Another question: As will also have Java applications sending logging events to this same SimpleSocketServer, which king of appender should them use? I could not find any XMLSocketAppender at log4j. Best regards Claudia Miazaki -----Mensagem original----- De: Scott Deboy [mailto:[EMAIL PROTECTED] Enviada em: quarta-feira, 23 de junho de 2004 11:29 Para: Log4J Users List; [EMAIL PROTECTED] Assunto: RE: Log4j SocketServer with Log4cxx SockeAppender (requires the latest version of log4j available from CVS): On the log4j side, use a simplesocketserver, specifying whichever port you want to receive java events on, and a log4j config file which includes this receiver plugin definition (or it's properties-style equivalent): <plugin name="Log4JXMLSocketReceiver" class="org.apache.log4j.net.XMLSocketReceiver"> <param name="Port" value="4447"/> </plugin> You can also configure Chainsaw v2 to use the same receiver and view events in the UI. Scott -----Original Message----- From: Clᵤia Miazaki [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 23, 2004 5:14 AM To: [email protected] Cc: [EMAIL PROTECTED] Subject: Log4j SocketServer with Log4cxx SockeAppender Hi, I'm trying to use log4j's SocketServer.java on a listening port to manage logging events coming both from Java and C++ applications, using log4j and log4cxx SocketAppenders, respectively. The SocketServer manages logging events from my Java applications fine, but when it receives logging events from the C++ applications it gets the following exception: java.io.StreamCorruptedException: invalid stream header at java.io.ObjectInputStream.readStreamHeader(Unknown Source) ... Is this kind of usage impossible? Log4j's SocketServer can only deal with logging events from other Java apps? Thanks for any help! Best regards, Claudia Miazaki
