English 中文(简体)
在 IIDA 中查找log4j. 正确性
原标题:Finding log4j.properties in IDEA

" 强 " 更新 -- -- 这个问题是我自己造成的。

在某个阶段,这个特定测试类有一个测试以确保某些东西被登录。 在设置中, 我先前删除了所有的附加器, 并添加了我自己的附加器来进行测试时间的描述 。 该测试早已过去, 但这个种子仍然留在设置中 : < code> Logger. getRoootLogger (. removeallAppenders (); 。

抱歉错误提醒 。 : ) @ info: whatsthis


在民主选举学会,我有以下测试:

@Test
public void shouldLog() {
    URL resource = Thread.currentThread().getContextClassLoader()
        .getResource("log4j.properties");
    System.out.println("resource = " + resource);
    final Logger logger = Logger.getLogger(getClass());
    logger.info("Hello world");
}

因此,它的产出是:

"C:Program FilesJavajdk1.5.0_18injava" -classpath "C:Program FilesJetBrainsIntelliJ IDEA Community Edition 11.1libidea_rt.jar" -ea -Dfile.encoding=UTF-8 com.intellij.rt.execution.CommandLineWrapper C:DOCUME~1JMAWSO~1.NT3LOCALS~1Tempclasspath2294205410661538428.tmp @vm_params C:DOCUME~1JMAWSO~1.NT3LOCALS~1Tempvm_params5645362020129462784.tmp com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 au.com.gmm.repo.RepoThreadCleanupServiceTest,shouldLog
resource = file:/C:/user/jem/projects/GMM/out/test/cashflow/log4j.properties
log4j:WARN No appenders could be found for logger (au.com.gmm.repo.RepoThreadCleanupServiceTest).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Process finished with exit code 0

这是一个有名的问题,许多新人一再看到这个问题。

http://logbook.apache.org/log4j/1.2/faq.html#noconfig log4j 使用Tread.getContextClass Loader ().getResourc () 来查找默认配置文件 。然而,我的测试支票 Thread.currentTreTread () (. getContextClass Loader ().getResource ("log4j.properties") 找到属性文件没有问题。

文件的内容是:

log4j.rootLogger=DEBUG, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss.SSS} %c - %m%n
最佳回答

在IntelliJIDA中,我使用有 slf4j 的log4j 和 slf4j, 这对我非常有效。 只要把这些罐子纳入 IntelliJ 的应用依赖性:

log4j-1.2.9.jar
slf4j-api-1.5.11.jar
slf4j-log4j12-1.5.11.jar

而不是在您的 log4j 配置应用程序中放置某处 。 但不要忘记将 Intellij 中的log4j. propertys 标记为源头, 或者您在测试源时使用它 :

log4j. 礼仪 :

log4j.rootLogger=INFO,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %X{file} %c{1} - %m%n

log4j.logger.your.app=DEBUG,yourApp
log4j.additivity.your.app=false
log4j.logger.yourApp=DEBUG,yourApp
log4j.additivity.yourApp=false
log4j.appender.yourApp=org.apache.log4j.ConsoleAppender
log4j.appender.yourApp.layout=org.apache.log4j.PatternLayout
log4j.appender.yourApp.layout.ConversionPattern=%d [%t] %-5p %X{file} %c{1} %m%n
log4j.appender.yourApp.ImmediateFlush=true

然后在你的 Java 类使用这个 获取登录器:

private static final Logger LOGGER = LoggerFactory.getLogger(YourApp.class);

您将看不到任何警告 : < code>, 无法为logger 找到附件 。

希望这能帮上忙

问题回答

暂无回答




相关问题
Specify time zone of log4j s date

Is it possible to specify the time zone that log4j will use? I need the dates in the log file to be a different time zone than the application s. log4j s PatternLayout uses SimpleDateFormat. ...

java wrapper around log4j logger and java.util.logging

I am writing a library. The library can be used by applications that use log4j loggers and java.util.logging loggers. So, I wrote a quick wrapper class, that encapsulates both loggers. I allow the ...

Grails log4j configuration

I ve repeatedly had problems with the DSL introduced by Grails in version 1.1 for configuring Log4J. My current configuration looks like this: log4j = { debug com.mypackages ...

Creating daily logs with Log4j?

What configuration values are needed to setup Log4j to use the following pattern? MyApp-Mon.log MyApp-Tue.log MyApp-Wed.log Etc With each file containing the days log. This sounds easy enough to do ...

Overriding log4j settings at deploy time

For an application which is deployed on a large number of machines I took the decision to deploy a standard log4j.xml file with the application package, just to make sure that have the same settings ...

How to validate Java logging properties files?

I have a basic facility for allowing users to remotely apply changes to the logging files in my application. Some logs are configured using java.util.logging properties files, and some are configured ...

How do you Change a Package s Log Level using Log4j?

I ve encountered the following bug: http://issues.apache.org/jira/browse/AXIS2-4363 It states the following: This error only occurs when log level for org.apache.axiom is DEBUG so a ...

热门标签