1

I've got a java server launched from a jar that uses log4j (RollingFile and Console appender). Alone: no problem it works. I've got a JBoss server using log4j (default install). Everything is ok when it runs alone.

When I start my Java server first and the JBoss, no problem either.

However when launching JBoss first and THEN launch the java server, the last doesn't log anything and JBoss sends me this : ERROR [ServerThread] Failed to initialize

java.io.EOFException
        at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2297)
        at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2766)
        at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:797)
        at java.io.ObjectInputStream.<init>(ObjectInputStream.java:297)
        at org.jboss.invocation.pooled.interfaces.OptimizedObjectInputStream.<init>(OptimizedObjectInputStream.java:147)
        at org.jboss.invocation.pooled.server.ServerThread.dorun(ServerThread.java:265)
        at org.jboss.invocation.pooled.server.ServerThread.run(ServerThread.java:156)
log4j:WARN Detected problem with connection: java.net.SocketException: Broken pipe

Is there possible conflict between two servers using LOG4J ? I didn't find anything on the net.

Thanks

ADDENDUM

  • JBoss and the Java server are in different directories
  • JBoss and the Java server don't share any port (8080/8433--> JBoss and 20400-->Java)
  • JBoss and the Java server have their own log4jxxxx.jar in their own library folder
  • Java Log4j version : log4j-1.2.16.jar (I also tried 1.2.17)
  • JBoss version : jboss-5.1.0.GA
  • Both write in different files

Here are the config files : (Basically console & appender file only)

Java

      <!--  mocutil import -->
        <appender name="mocutilImport" class="org.apache.log4j.RollingFileAppender">
                <param name="Threshold" value="INFO" />
                <param name="File" value="log/mocutilImport.log" />
                <param name="MaxFileSize" value="5000KB" />
            <!-- Keep five backup file -->
            <param name="MaxBackupIndex" value="5"/>
                <layout class="org.apache.log4j.PatternLayout">
                        <param name="ConversionPattern" value="%d %-5p - %m%n" />
                </layout>
        </appender>
        <appender name="NectarMotrServer" class="org.apache.log4j.RollingFileAppender">
                <param name="Threshold" value="INFO" />
                <param name="File" value="log/NectarMotrServer.log" />
                <param name="MaxFileSize" value="5000KB" />
            <!-- Keep five backup file -->
            <param name="MaxBackupIndex" value="5"/>
                <layout class="org.apache.log4j.PatternLayout">
                        <param name="ConversionPattern" value="%d %-5p - %m%n" />
                </layout>
        </appender>
        <appender name="NectarMotrServerDev" class="org.apache.log4j.RollingFileAppender">
                <param name="Threshold" value="DEBUG" />
                <param name="File" value="log/NectarMotrServerDev.log" />
                <param name="MaxFileSize" value="5000KB" />
            <!-- Keep five backup file -->
            <param name="MaxBackupIndex" value="5"/>
                <layout class="org.apache.log4j.PatternLayout">
                        <param name="ConversionPattern" value="%d %c{1} [%t] %p - %m%n" />
                </layout>
        </appender>
    <!--  Default  -->
        <appender name="console" class="org.apache.log4j.ConsoleAppender">
                <param name="Threshold" value="TRACE" />
           <param name="Target" value="System.out"/>
           <layout class="org.apache.log4j.PatternLayout">
             <param name="ConversionPattern" value="[%d] %c{1} - %m%n" />
           </layout>
         </appender>
    <category name="fr.edf.nectar">
            <appender-ref ref="NectarmotrServer"/>
            <appender-ref ref="NectarmotrServerDev"/>
            <appender-ref ref="console"/>
    </category>
    <category name="fr.edf.nectar.interfaces.motr.imports.mocutil">
            <appender-ref ref="mocutilImport"/>
    </category>

     <root>
        <priority value="ALL"/>
     </root>

JBOSS (I removed commented appenders)

   <!-- ======================= -->
   <!-- Setup the Root category -->
   <!-- ======================= -->
   <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
      <param name="File" value="${jboss.server.log.dir}/server.log"/>
      <param name="Append" value="true"/>
      <!-- In AS 5.0.x the server log threshold was set by a system
           property. In 5.1 and later we are instead using the system
           property to set the priority on the root logger (see <root/> below)
      <param name="Threshold" value="${jboss.server.log.threshold}"/>
      -->

      <!-- Rollover at midnight each day -->
      <param name="DatePattern" value="'.'yyyy-MM-dd"/>

      <!-- Rollover at the top of each hour
      <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
      -->

      <layout class="org.apache.log4j.PatternLayout">
         <!-- The default pattern: Date Priority [Category] (Thread) Message\n -->
         <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>

         <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
         <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
          -->
      </layout>
   </appender>
   <!-- ============================== -->
   <!-- Append messages to the console -->
   <!-- ============================== -->

   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
      <param name="Target" value="System.out"/>
      <param name="Threshold" value="INFO"/>

      <layout class="org.apache.log4j.PatternLayout">
         <!-- The default pattern: Date Priority [Category] Message\n -->
         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
      </layout>
   </appender>

   <root>
      <!--
         Set the root logger priority via a system property. Note this is parsed by log4j,
         so the full JBoss system property format is not supported; e.g.
         setting a default via ${jboss.server.log.threshold:WARN} will not work.
       -->
      <priority value="${jboss.server.log.threshold}"/>
      <appender-ref ref="CONSOLE"/>
      <appender-ref ref="FILE"/>
   </root>
Michael Laffargue
  • 10,116
  • 6
  • 42
  • 76

2 Answers2

3

There is no problem having several applications running in the same machine and using Log4j facilities. The questions is, where is located the Log4j config file in both server? where is Log4j generating the log files in both servers? What appenders are you using? Any point in common can cause problems. Try to isolate both servers with separate config files, log files generated in different folders and both servers having its own copy of Log4j jar.

The error shown is strange as refers to sockets. Log4j uses any appenders that relies on sockets? Any GUI tool for monitoring log like Chainsaw?

Provide more information about the Log4j installed in both servers.

David Oliván
  • 2,717
  • 1
  • 19
  • 26
  • Thanks for answer, I added the config files. But basically, JBoss and Java don't share config/log files/lib and there is no socket appender either. – Michael Laffargue Jun 12 '12 at 07:52
  • There are several ports JBoss can use, web port for your application, web-console for administration, RMI, ... Try to start jboss standalone and check ports already opened with netstat and the pid. Same for your java server. Log4j config files look ok. – David Oliván Jun 12 '12 at 10:34
  • To resume (I used netstat and ss), my java only open socket 20400 and 20800 which are not part of JBoss port/socket listening when I run it alone. If I run JBoss first, then every time I try to start the Java server, the broken pipe error appear... Not using Chainsaw though. It's a mystery to me – Michael Laffargue Jun 12 '12 at 14:10
  • Yes, a mystery. Please, try to disable Log4J in both servers and activate alternatively, trying to enable appender by appender. – David Oliván Jun 12 '12 at 16:09
  • I finally found the cause. Thanks for you help, you really deserve the bounty ;) – Michael Laffargue Jun 14 '12 at 12:55
1

Here is what happened (Thanks to David Oliván Ubieto for his help):

In the Java server, we're using a Php/Java bridge, looking at its class I found :

Util.Logger()
      Use chainsaw, if available or a default logger.

Refering to David Chainsaw might be a problem, and it does because it uses the port 4445 which is the same as JBoss invoker, type=pooled service (Source).

So what happen I think is that launching the server, the bridge library try connecting to 4445 to see if chainsaw is present. It detects something and decide to use 4445 as Logging port resulting in no log for Java, meanwhile JBoss receives strange messages on 4445 and throw an Exception.

Launching Java first, will result in the lib using my Log4j configuration and JBoss working as expected.

To correct everything I modified .../jboss-5.1.0.GA/server/default/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml like this :

...
        <!-- Pooled invoker -->
        <bean class="org.jboss.services.binding.ServiceBindingMetadata">
           <property name="serviceName">jboss:service=invoker,type=pooled</property>
           <property name="port">[PORT OTHER THAN 4445]</property>
           <property name="description">Socket for the legacy Pooled invoker</property>
        </bean>

...
Michael Laffargue
  • 10,116
  • 6
  • 42
  • 76