Package org.apache.log4j

Examples of org.apache.log4j.Category


  void configureRootCategory(Properties props, Hierarchy hierarchy) {
    String value = OptionConverter.findAndSubst(ROOT_CATEGORY_PREFIX, props);
    if(value == null)
      LogLog.debug("Could not find root category information. Is this OK?");
    else {
      Category root = hierarchy.getRoot();
      synchronized(root) {
  parseCategory(props, root, ROOT_CATEGORY_PREFIX, INTERNAL_ROOT_NAME,
          value);
      }
    }       
View Full Code Here


  /**
     Used internally to parse the roor category element.
  */
  protected
  void parseRoot (Element rootElement, Hierarchy hierarchy) {
    Category root = hierarchy.getRoot();
    // category configuration needs to be atomic
    synchronized(root) {   
      parseChildrenOfCategoryElement(rootElement, root, true);
    }
  }
View Full Code Here

  }


  static
  void test() {   
    Category root = Category.getRoot();   
    for(int i = 0; i < 100; i++) {     
      root.debug("Message " + i);       
    }

    try{Thread.currentThread().sleep(delayBeforeClose);}catch(Exception e){}
    Category.shutdown();
  }
View Full Code Here

  static
  void test() {
    int i = -1;
    NDC.push("NDC");
    Category root = Category.getRoot();

    cat.trace("Message " + ++i);
    cat.debug("Message " + ++i);
    root.debug("Message " + ++i);
    cat.info("Message " + ++i);
    cat.warn("Message " + ++i);
    cat.lethal("Message " + ++i); //5
   
    Exception e = new Exception("Just testing");
    cat.debug("Message " + ++i, e);
    root.error("Message " + ++i, e);
   
    Category.shutdown();
  }
View Full Code Here

  void main(String argv[]) {

    if(argv.length == 1) {
      NDC.push("testing");
      PropertyConfigurator.configure(argv[0]);
      Category root = Category.getRoot();
      root.debug("Message 1");
      root.debug("Message 2");     
      NDC.pop();
      Category.shutdown();
    }
    else {
      Usage("Wrong number of arguments.");
View Full Code Here

    // In the lines below, the category names are chosen as an aid in
    // remembering their priority values. In general, the category
    // names should have no bearing to priority values.
   
    Category ERR = Category.getInstance("ERR");
    ERR.setPriority(Priority.ERROR);
    Category INF = Category.getInstance("INF");
    INF.setPriority(Priority.INFO);
    Category INF_ERR = Category.getInstance("INF.ERR");
    INF_ERR.setPriority(Priority.ERROR);
    Category DEB = Category.getInstance("DEB");
    DEB.setPriority(Priority.DEBUG);
   
    // Note: categories with undefined priority
    Category INF_UNDEF = Category.getInstance("INF.UNDEF");
    Category INF_ERR_UNDEF = Category.getInstance("INF.ERR.UNDEF");   
    Category UNDEF = Category.getInstance("UNDEF");  


    // These should all log.----------------------------
    ERR.log(Priority.FATAL, "Message " + i); i++;  //0
    ERR.error( "Message " + i); i++;         

    INF.log(Priority.FATAL, "Message " + i); i++; // 2
    INF.error( "Message " + i); i++;        
    INF.warn ( "Message " + i); i++;
    INF.info ( "Message " + i); i++;

    INF_UNDEF.log(Priority.FATAL, "Message " + i); i++;  //6
    INF_UNDEF.error( "Message " + i); i++;        
    INF_UNDEF.warn ( "Message " + i); i++;
    INF_UNDEF.info ( "Message " + i); i++;
   
   
    INF_ERR.log(Priority.FATAL, "Message " + i); i++;  // 10
    INF_ERR.error( "Message " + i); i++; 

     INF_ERR_UNDEF.log(Priority.FATAL, "Message " + i); i++;
    INF_ERR_UNDEF.error( "Message " + i); i++;            

    DEB.log(Priority.FATAL, "Message " + i); i++;  //14
    DEB.error( "Message " + i); i++;        
    DEB.warn ( "Message " + i); i++;
    DEB.info ( "Message " + i); i++;
    DEB.debug( "Message " + i); i++;

   
    // defaultPriority=DEBUG
    UNDEF.log(Priority.FATAL, "Message " + i); i++;  // 19
    UNDEF.error("Message " + i); i++;        
    UNDEF.warn ("Message " + i); i++;
    UNDEF.info ("Message " + i); i++;
    UNDEF.debug("Message " + i, new Exception("Just testing.")); i++;   

    // -------------------------------------------------
    // The following should not log
    ERR.warn("Message " + i);  i++;
    ERR.info("Message " + i);  i++;
View Full Code Here

  static
  void test() {
    int i = -1;
    NDC.push("NDC");
    Category root = Category.getRoot();
    cat.debug("Message " + ++i);
    root.debug("Message " + i);       

    cat.info ("Message " + ++i);
    root.info("Message " + i);       

    cat.warn ("Message " + ++i);
    root.warn("Message " + i);       

    cat.error("Message " + ++i);
    root.error("Message " + i);
   
    cat.log(Priority.FATAL, "Message " + ++i);
    root.log(Priority.FATAL, "Message " + i);   
   
    Exception e = new Exception("Just testing");
    cat.debug("Message " + ++i, e);
    root.debug("Message " + i, e);
   
    cat.info("Message " + ++i, e);
    root.info("Message " + i, e);   

    cat.warn("Message " + ++i , e);
    root.warn("Message " + i , e);   

    cat.error("Message " + ++i, e);
    root.error("Message " + i, e);   

    cat.log(Priority.FATAL, "Message " + ++i, e);
    root.log(Priority.FATAL, "Message " + i, e);   


    // It is always a good idea to call this method when exiting an
    // application.
    Category.shutdown();
View Full Code Here

  }

  static
  void test() {
    int i = -1;
    Category root = Category.getRoot();
   
    CAT.debug("Message " + ++i);
    root.debug("Message " + i);       

    CAT.info ("Message " + ++i);
    root.info("Message " + i);       

    CAT.warn ("Message " + ++i);
    root.warn("Message " + i);       

    CAT.error("Message " + ++i);
    root.error("Message " + i);
   
    CAT.log(Priority.FATAL, "Message " + ++i);
    root.log(Priority.FATAL, "Message " + i);   
   
    Exception e = new Exception("Just testing");
    CAT.debug("Message " + ++i, e);
    root.debug("Message " + i, e);
   
    CAT.info("Message " + ++i, e);
    root.info("Message " + i, e);   

    CAT.warn("Message " + ++i , e);
    root.warn("Message " + i , e);   

    CAT.error("Message " + ++i, e);
    root.error("Message " + i, e);   

    CAT.log(Priority.FATAL, "Message " + ++i, e);
    root.log(Priority.FATAL, "Message " + i, e);   
   
    Category.shutdown();
  }
View Full Code Here

  /**
     Test if category a.b inherits its appender from a.
   */
  public
  void testAdditivity1() {
    Category a = Category.getInstance("a");
    Category ab = Category.getInstance("a.b");
    CountingAppender ca = new CountingAppender();
    a.addAppender(ca);
   
                   assertEquals(ca.counter, 0);
    ab.debug(MSG); assertEquals(ca.counter, 1);
    ab.info(MSG);  assertEquals(ca.counter, 2);
    ab.warn(MSG);  assertEquals(ca.counter, 3);
    ab.error(MSG); assertEquals(ca.counter, 4);   
   

  }
View Full Code Here

   */
  public
  void testAdditivity2() {
   
    Category a = Category.getInstance("a");
    Category ab = Category.getInstance("a.b");
    Category abc = Category.getInstance("a.b.c");
    Category x   = Category.getInstance("x");

    CountingAppender ca1 = new CountingAppender();
    CountingAppender ca2 = new CountingAppender();

    a.addAppender(ca1);
    abc.addAppender(ca2);

    assertEquals(ca1.counter, 0);
    assertEquals(ca2.counter, 0);       
   
    ab.debug(MSG)
    assertEquals(ca1.counter, 1);
    assertEquals(ca2.counter, 0);       

    abc.debug(MSG);
    assertEquals(ca1.counter, 2);
    assertEquals(ca2.counter, 1);       

    x.debug(MSG);
    assertEquals(ca1.counter, 2);
    assertEquals(ca2.counter, 1);   
  }
View Full Code Here

TOP

Related Classes of org.apache.log4j.Category

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.