简体   繁体   English

如何在Eclipse中设置log4j.properties?

[英]How to set log4j.properties in Eclipse?

I'm trying to run this example , but I have some problems with configuration. 我正在尝试运行此示例 ,但是我在配置方面遇到了一些问题。

I copied log4j-jms.properties , jndi.properties , Log4jJMSAppenderExample.java 我复制了log4j-jms.propertiesjndi.propertiesLog4jJMSAppenderExample.java

ProjectJMS
|
\_ src
|   \_ Log4jJMSAppenderExample.java
|   \_ jndi.propeties
\_ log4j-jms.properties

and run activemq in my console. 并在控制台中运行activemq

When I ran my example I got 当我运行示例时,我得到了

log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.WireFormatNegotiator).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.`PropertyConfigurator.configure("log4j-jms.properties");`

so I added 所以我加了

PropertyConfigurator.configure("log4j-jms.properties");

Now I can see logs in Eclipse console, but still with this warning 现在,我可以在Eclipse控制台中看到日志,但是仍然显示此警告

log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.WireFormatNegotiator).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2012-08-13 10:21:44,741 INFO  Log4jJMSAppenderExample - Test log
Received log [INFO]: Test log

and in console with activemq I got 在带有activemq控制台activemq

 WARN | Transport Connection to: tcp://127.0.0.1:2005 failed: java.net.SocketException: Connection reset

Why am I getting these warnings? 为什么会收到这些警告?

  1. Are my imports wrong? 我的进口错了吗?

     import javax.jms.Connection; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageListener; import javax.jms.Session; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.command.ActiveMQObjectMessage; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.spi.LoggingEvent; 
  2. Are my files in wrong place? 我的文件放在错误的位置吗?

  3. How to set configuration file in Eclipse? 如何在Eclipse中设置配置文件? Without using PropertyConfigurator.configure("log4j-jms.properties"); 不使用PropertyConfigurator.configure("log4j-jms.properties"); ? There is no line like this in example I follow. 在下面的示例中,没有这样的行。

Your log4j.properties should reside inside the src folder. 您的log4j.properties应该位于src文件夹中。 That way, Log4J will configure itself automatically, without you needing to write code. 这样,Log4J将自动配置自身,而无需编写代码。

  1. There is nothing about imports; 进口什么都没有。

  2. It's not about the file place, as you see this message "log4j:WARN No appenders could be found for logger...", so please check the content of your log4j configuration file. 它与文件位置无关,因为您看到此消息“ log4j:WARN找不到记录器的附加程序...”,因此请检查log4j配置文件的内容。 Here's a demo: 这是一个演示:

    log4j.rootLogger=INFO, myConsoleAppender log4j.appender.myConsoleAppender=org.apache.log4j.ConsoleAppender log4j.appender.myConsoleAppender.layout=org.apache.log4j.PatternLayout log4j.appender.myConsoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n log4j.rootLogger = INFO,myConsoleAppender log4j.appender.myConsoleAppender = org.apache.log4j.ConsoleAppender log4j.appender.myConsoleAppender.layout = org.apache.log4j.PatternLayout log4j.appender.myConsoleAppender.layout.ConversionPattern =%-4r [% t]%-5p%c%x-%m%n

  3. The default log4j configuration file is "log4j.properties", and as someone had said it should be place in the src folder. 默认的log4j配置文件是“ log4j.properties”,就像有人说的那样,它应该放在src文件夹中。

According to your project structure, there is no log4j-jms.properties.There is log4j.properties. 根据您的项目结构,没有log4j-jms.properties,没有log4j.properties。 So change your log4j properties file name. 因此,更改您的log4j属性文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM