2014-02-17 2 views
4

콘솔로 출력하려고합니다. logger.info ("Hello world info."); 다음 코드는 '리소스를 찾을 수 없습니다'반환하지만 //이 ...Logback 리소스 logback.xml을 찾을 수 없습니다.

을 잘 작동 오류 :

Logger logger = LoggerFactory.getLogger("framework.Utilities._Test"); 
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); 
StatusPrinter.print(lc); 

나는 다음과 같은 XML 사용하고 있습니다 :

<configuration> 
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> 
    <file>C:\Reports\logBack.log</file> 
    <!-- encoders are assigned by default the type 
     ch.qos.logback.classic.encoder.PatternLayoutEncoder --> 
    <encoder> 
     <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> 
    </encoder> 
</appender> 

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 
    <encoder> 
     <pattern>%msg%n</pattern> 
    </encoder> 
</appender> 

<root level="debug"> 
    <appender-ref ref="FILE" /> 
    <appender-ref ref="STDOUT" /> 
</root> 
</configuration> 

그리고 나 '를 내 클래스 경로 (Windows7 \ 환경 변수 \ 시스템 변수 \ 경로)의 여러 위치의 루트에 복사 했는데도 '자원을 찾을 수 없음'오류가 발생합니다. 어떤 아이디어?

Let us begin by discussing the initialization steps that logback follows to try to configure itself:

  1. Logback tries to find a file called logback.groovy in the classpath.

  2. If no such file is found, logback tries to find a file called logback-test.xml in the classpath.

  3. If no such file is found, it checks for the file logback.xml in the classpath..

  4. If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.

을 그래서 아마도 귀하의 경우 당신이 콘솔의 출력을보고있는 기본 구성을로드에 :

+1

코드를 어떻게 실행하고 있습니까? \ by/for 파일 경로를 바꾸어 시도 할 수 있습니다. 때로는 작동하지 않습니다. –

답변

4
And I've copied it into the root of several locations in my classpath 

logback 여기에 구성 파일을 찾는 기본 방법이 문서가 어떻게되는지되어있다 . 클래스 경로에서 경로를 지정하거나 프로그래밍 방식으로 수행 할 수 있습니다. this

관련 문제