프로그램/log

log4j의 Category 개념 확인

이승구 2010. 12. 14. 17:46
반응형

Category : 로깅 우선순위 정할 수 있음, Category 이름으로 상속 비슷하게 사용할 수 있음

package log.log4j;

import org.apache.log4j.Category;
import org.apache.log4j.Priority;

/**
 * Category 의 package 가 유사하면 이를 상속받게 된다.
 *
 * barcat 은 디폴트로 생성되면 debug이기 떄문에 출력
 * concat 은 cat 과 Category 명이 유사하여 이를 상속받아 INFO 이기 떄문에 출력 안됨
 *
 * @author seungkyu.lee
 *
 */
public class TestLog4J {
 public static void main( String[] args ) {
  Category cat = Category.getInstance( "log.log4j" );
 
  cat.setPriority( Priority.INFO );
 
  cat.warn( "Low fuel level" );
 
  cat.debug( "Starting search for nearest gas station." );
 
  Category barcat = Category.getInstance( "com.foo" );
 
  barcat.info( "Located nearest gas station." );
 
  barcat.debug( "Exiting gas station search." );
 
  Category concat = Category.getInstance( "log.log4j.concat" );
 
  concat.debug( "concat debug." );
 
  concat.debug( "concat debug.." );
 }
}