2017-09-05 19 views
0

Java 독립 실행 형 응용 프로그램이 있습니다. 이 2 개 개의 수입과 주요 방법으로 :JAVA : 독립 실행 형 응용 프로그램에서 로그백 구성

import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

과 같은 폴더에

private static final Logger log = LoggerFactory.getLogger(PecadorDeLaPradera.class); 

나는 또한 logback.xml을하지만 난에 logback.xml를 사용하는 프로그램을 이야기하는 방법을 모른다 나는 사이 logback.xml이 나는 ​​org.apache.log4j.PropertyConfigurator

와 유사한 어떤 클래스를 찾을 수 없습니다

로그를 config (설정) 나를 실행중인 자바 클래스의 폴더 :

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 

    <!-- trace, debug, info, warn, error, fatal --> 
    <timestamp key="myTimestamp" datePattern="yyyy-MM-dd'_'HH-mm-ss.SSS"/> 


    <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"> 
     <resetJUL>true</resetJUL> 
    </contextListener> 

    <!-- To enable JMX Management --> 
    <jmxConfigurator/> 

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> 
     <encoder> 
      <pattern>%d{"yyyy-MM-dd HH:mm"} [%thread] %-5level %logger{35} - %msg%n</pattern> 
     </encoder> 
    </appender> 

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> 
     <file>pecador.log</file> 

     <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> 
      <fileNamePattern>handler.%i.log.zip</fileNamePattern>    
      <minIndex>1</minIndex> 
      <maxIndex>3</maxIndex> 
     </rollingPolicy> 

     <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 
      <maxFileSize>1MB</maxFileSize> 
     </triggeringPolicy> 
     <encoder> 
      <pattern>%d{"yyyy-MM-dd HH:mm"} [%thread] %-5level %logger{35} - %msg%n</pattern> 
     </encoder> 
    </appender> 



    <!-- <logger name="org.springframework.orm.jpa"  level="debug" /> -->  
    <logger name="com.calzada.pecador" level="debug" /> 


    <root level="info"> 
     <appender-ref ref="CONSOLE" /> 
     <appender-ref ref="FILE" /> 
    </root> 
</configuration> 

나는 또한 appl를 실행한다. 프로그램 인수 :

java.util.MissingResourceException: Can't find bundle for base name -Dlogback.configurationFile=/Users/nullpointer/Development/J2EE/eclipseWSJ2EE/myApp/src/com/calzada/pecador/logback.xml, locale en_ES 

사용되는 라이브러리는 여기 logback-classic-1.2.3.jar

답변

1

이다 logback 자체 구성 방법은 다음과 같습니다 :

Logback tries to find a file called logback-test.xml in the classpath.

If no such file is found, logback tries to find a file called logback.groovy in the classpath.

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

If no such file is found, service-provider loading facility (introduced in JDK 1.6) is used to resolve the implementation of com.qos.logback.classic.spi.Configurator interface by looking up the file META-INF\services\ch.qos.logback.classic.spi.Configurator in the class path. Its contents should specify the fully qualified class name of the desired Configurator implementation.

If none of the above succeeds, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.

또한 가리킬 수를

-Dlogback.configurationFile=/Users/calzada/Dev/J2EE/eclipseWSJ2EE/myApp/src/com/calzada/pecador/logback.xml 

나는이 오류가 발생했습니다 시스템 매개 변수를 사용하여 특정 구성 파일에서 로그백. 문서에서 :

You may specify the location of the default configuration file with a system property named "logback.configurationFile". The value of this property can be a URL, a resource on the class path or a path to a file external to the application.

java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1

위의 내용은 docs에서 취한 것입니다.

질문에 따르면 logback.xml이 있지만이 파일은 수업과 같은 폴더에 있습니다. 클래스가 루트 패키지에 있지 않으면 logback.xml이 클래스 경로의 루트에 없으므로 Logback이 클래스 경로를 찾지 못함을 의미합니다. 위해서는 Logback 당신이 중 하나를 수행 할 수 있습니다이 파일에서 자신을 구성하려면 다음 : 클래스 패스의 루트에 logback.xml (이 메이븐 프로젝트가 복사하는 것만 큼 간단 logback.xmlsrc/main/resources에)

  • 장소
  • 자바 프로그램을 -Dlogback.configurationFile=/path/to/logback.xml
와 함께 실행하십시오.