2

We are using Jboss 7.4.0 with two nodes that each have their own rolling file appenders. What we would like to do is redirect these two outputs in a unique file, "outside" both Jboss nodes. I tried to use SocketAppenders, with a manually started Log4J server, but it doesn't work...

<custom-handler name="SOCKET" class="org.apache.log4j.net.SocketAppender" module="org.apache.log4j">
  <level name="DEBUG"/>
  <formatter>
     <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p %X{user} %X{app} [%C:%M:%L] (%t) %s%E%n"/>
  </formatter>
  <properties>
     <property name="Port" value="4712"/>
     <property name="RemoteHost" value="127.0.0.1"/>
  </properties>

The only things in the log4j server is this :

[2015-04-01 10:31:24,969] [main] [Listening on port 4712]
[2015-04-01 10:31:24,981] [main] [Waiting to accept a new client.]

I've read that the SocketAppender doens't exists anymore in Jboss 7+, but to be honest, the Jboss documentation is incomplete, missing, or incorrect at best.

So, what's the correct (or best) way to do this, without reinventing the wheel? Should we use asynchronous rolling file appenders? Is there any other alternatives?

ALansmanne
  • 271
  • 1
  • 6
  • 17
  • Have you added reference to socket in your root-logger? – smali Apr 01 '15 at 09:14
  • Have you started the client for accepting the server request – smali Apr 01 '15 at 10:31
  • I've followed this guide (from the recommanded answer) : http://stackoverflow.com/questions/11759196/log4j-how-to-use-socketappender I've started the Log4J server, and then started my two Jboss nodes. I can see the logs in console, in their respective files... but not in the Log4J server. – ALansmanne Apr 01 '15 at 11:25
  • can you list out the steps you followed for running this configurations.. seem you are not running it correctly – smali Apr 02 '15 at 04:11
  • On my Jboss, I've added in both nodes, in domain.xml, the appender described in my first post. Then, I've added the SOCKET appender to my root logger. Separatly, I've created a log4j.properties file, next to the log4j.jar, and i've run the log4j server using the first comand from the linked post Then, I've started the Jboss domain controller, and both nodes – ALansmanne Apr 02 '15 at 07:02

1 Answers1

1

Follow these Steps to use it correctly this might solve your problem..

1> First Create log4j-server.properties

log4j.rootLogger=DEBUG, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logfile.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%d] [%t] [%m]%n

2> Now Run the following command at reciever side

java -classpath log4j.jar org.apache.log4j.net.SimpleSocketServer 4712 log4j-server.properties

now it will listen to the port 4712 and store the logs in the logfile.log which you have defined in your log4j-server.properties file

3>In log4j.xml file add the following appender to send the logs to the server with the specified port.

<custom-handler name="SOCKET"  class="org.apache.log4j.net.SocketAppender" module="org.apache.log4j">
<level name="DEBUG"/>
<properties>
  <property name="Port" value="4712"/>
  <property name="RemoteHost" value="127.0.0.1"/>
</properties>

Do not specify any formatter in this configurations. and do not forget to add SOCKET in root-logger of log4j.xml

smali
  • 4,687
  • 7
  • 38
  • 60
  • I've followed these steps, but.. I don't have a log4j.xml. I've tried to put this same configuration in my domain.xml (jboss_node1/domain/configuration/) – ALansmanne Apr 03 '15 at 08:11
  • Ok, I've added the appender from the jboss web console, and now, I can see part of my logs in logfile.log. So it should only be a matter of configuration now, thanks :) – ALansmanne Apr 03 '15 at 08:32