2012-12-18 3 views
0

여러 응용 프로그램간에 공유되는 logging.properties 파일을 구성하려고합니다. 내 클래스의 특정 로그 파일을 원하지만 다른 클래스의 다른 로그를 파일에 포함하지 않으려합니다.단일 logging.properties를 사용하여 다른 파일에 로깅

logging.properties 파일 만 수정하면 어떻게 해결할 수 있습니까?

나는 다음과 같은 logging.properties 파일이 있습니다

############################################################ 
# Default Logging Configuration File 
# 
# You can use a different file by specifying a filename 
# with the java.util.logging.config.file system property. 
# For example java -Djava.util.logging.config.file=myfile 
############################################################ 
############################################################ 
# Global properties 
############################################################ 
# "handlers" specifies a comma separated list of log Handler 
# classes. These handlers will be installed during VM startup. 
# Note that these classes must be on the system classpath. 
# By default we only configure a ConsoleHandler, which will only 
# show messages at the INFO and above levels. 
handlers= java.util.logging.ConsoleHandler 
# To also add the FileHandler, use the following line instead. 
#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler 
# Default global logging level. 
# This specifies which kinds of events are logged across 
# all loggers. For any given facility this global level 
# can be overriden by a facility specific level 
# Note that the ConsoleHandler also has a separate level 
# setting to limit messages printed to the console. 
.level= INFO 
############################################################ 
# Handler specific properties. 
# Describes specific configuration info for Handlers. 
############################################################ 
# default file output is in user's home directory. 

java.util.logging.FileHandler.pattern = %의 H/default.log (모든 로그가 현재이 파일에가는)

java.util.logging.FileHandler.limit = 50000 
java.util.logging.FileHandler.count = 1 
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter 
# Limit the message that are printed on the console to INFO and above. 
java.util.logging.ConsoleHandler.level = INFO 
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter 
############################################################ 
# Facility specific properties. 
# Provides extra control for each logger. 
############################################################ 

# For example, set the com.xyz.foo logger to only log SEVERE 
# messages: 

my.class.logger.level = 정보

,369 (I는이 클래스가 파일 /home/myuser/myclass.log에 로그인 할)
other.class.logger.level = ALL 
+0

http://stackoverflow.com/questions/3639694/java-util-logging-properties-how-to-log-to-two-different-files – Stefan

+0

고마워요 @StefanLindenberg, Tomcat에 있습니다. Tomcat의 특정 라이브러리를 사용하지 않고이를 수행 할 수있는 방법이 있습니까? 내 말은, 표준 자바 라이브러리 란 말인가요? –

답변

2

순수 jdk도 사용할 수 있습니다 (jdk 7 또는 jdk 8을 사용해보십시오).

그냥 사용자 지정 파일 처리기를 만듭니다. "java.util.logging.FileHandler"와 유사한 것을 사용하고 그것을 확장하십시오.

공용 클래스 JULTestingFileHandler가의 FileHandler를 확장 {

public JULTestingFileHandler() throws IOException, SecurityException 
{ 
    super();  
} 

} 사용자 등록 정보 파일;

com.xxx.handlers = com.xxx.JULXXXFileHandler

com.xxx.JULXXXFileHandler.pattern = ./logs/test1_test2.%u.%g.log

관련 문제