我有一个从使用 log4j(RollingFile 和控制台附加程序)的 jar 启动的 java 服务器。单独:没问题,它有效。我有一个使用 log4j 的 JBoss 服务器(默认安装)。单独运行时一切正常。
当我首先启动我的 Java 服务器和 JBoss 时,也没有问题。
但是,当首先启动 JBoss 然后启动 java 服务器时,最后一个不记录任何内容,JBoss 向我发送此消息:错误 [ServerThread] 无法初始化
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
使用 LOG4J 的两台服务器之间是否可能存在冲突?我没有在网上找到任何东西。
谢谢
附录
- JBoss 和 Java 服务器在不同的目录中
- JBoss 和 Java 服务器不共享任何端口(8080/8433--> JBoss 和 20400-->Java)
- JBoss 和 Java 服务器在自己的库文件夹中有自己的 log4jxxxx.jar
- Java Log4j 版本:log4j-1.2.16.jar(我也试过 1.2.17)
- JBoss 版本:jboss-5.1.0.GA
- 两者都写在不同的文件中
以下是配置文件:(基本上只有控制台和附加文件)
爪哇
<!-- 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(我删除了注释的附加程序)
<!-- ======================= -->
<!-- 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>