我使用Spring框架开发了一个模块,但我遇到了这个问题。我的模块是多线程的,我使用log4j api进行日志记录。 在少量初始日志之后,它开始两次打印日志。我认为threadID会被追加。
以下是日志示例:
INFO 2015-02-04 12:45:19,725 [localhost-startStop-1] [] com.org.test.daoImpl.DBConnection - DBConnection成功建立 INFO 2015-02-04 12:45:19,725 [localhost-startStop-1] [] com.org.test.daoImpl.DBConnection - 数据库属性已成功加载
INFO 2015-02-04 12:45:19,902 [localhost-startStop-1] [] com.org.test.main.Pusher - MyClient已成功初始化。
INFO 2015-02-04 12:45:20,241 [ActiveMQ Task-1] [] org.apache.activemq.transport.failover.FailoverTransport - 已成功连接到tcp://127.0.0.1:61616
INFO 2015-02-04 12:45:20,359 [localhost-startStop-1] [] org.springframework.orm.hibernate4.HibernateTransactionManager - 使用DataSource [JDBC URL = jdbc:mysql://127.0.0.1:3306 / myclienttest?autoReconnect = true,Username = myclient,partitions = 1,max(每个分区)= 1,min(每个分区)= 1,idle max age = 60 min,idle test period = 240 min,strategy = DEFAULT] of用于HibernateTransactionManager的Hibernate SessionFactory
INFO 2015-02-04 12:45:20,416 [localhost-startStop-1] [] org.springframework.web.servlet.DispatcherServlet - FrameworkServlet'dispatcher':初始化在3898 ms完成
2015年2月4日下午12:45:20 org.apache.coyote.AbstractProtocol start
信息:启动ProtocolHandler [“http-bio-8080”]
2015年2月4日下午12:45:20 org.apache.coyote.AbstractProtocol start
信息:启动ProtocolHandler [“ajp-bio-8009”]
2015年2月4日下午12:45:20 org.apache.catalina.startup.Catalina开始
信息:服务器启动时间为14629毫秒
INFO 2015-02-04 12:45:20,452 [Thread-5] [] com.org.test.queue.QueueSizeBean - RMI MBean Details :: QueueName = queue0 | #PendingMessages:0
3935 [Thread-5] INFO com.org.test.queue.QueueSizeBean - RMI MBean Details :: QueueName = queue0 | #PendingMessages:0
INFO 2015-02-04 12:45:20,453 [Thread-5] [] com.org.test.queue.QueueSizeBean - RMI MBean Details :: QueueName = queue1 | #PendingMessages:0
3936 [Thread-5] INFO com.org.test.queue.QueueSizeBean - RMI MBean Details :: QueueName = queue1 | #PendingMessages:0
INFO 2015-02-04 12:45:20,454 [Thread-5] [] com.org.test.queue.QueueSizeBean - RMI MBean Details :: QueueName = queue2 | #PendingMessages:0
3937 [Thread-5] INFO com.org.test.queue.QueueSizeBean - RMI MBean Details :: QueueName = queue2 | #PendingMessages:0
INFO 2015-02-04 12:45:24,006 [http-bio-8080-exec-4] [] com.org.test.controller.SMSController - URL Hit :: true
7489 [http-bio-8080-exec-4] INFO com.org.test.controller.Controller - URL Hit :: true
...
这些是log4j属性的详细信息:
<?xml version="1.0" encoding="UTF-8" ?>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%5p %d{ISO8601} [%t][%x] %c - %m%n" />
</layout>
</appender>
<appender name="myclient" class="org.apache.log4j.rolling.RollingFileAppender">
<param name="file" value="${catalina.base}/logs/logs.log" />
<param name="append" value="true" />
<param name="encoding" value="UTF-8" />
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern"
value="${catalina.base}/logs/%d{yyyy-MM-dd_HH}_logs.gz" />
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%5p %d{ISO8601} [%t][%x] %c:%L - %m%n" />
</layout>
</appender>
<logger name="com.org.test">
<level value="info" />
<!-- <appender-ref ref="myclient" /> -->
</logger>
<root>
<priority value="info" />
<appender-ref ref="CONSOLE" />
<!-- <appender-ref ref="myclient" /> -->
</root>
请帮帮我。