Package org.apache.log4j

Examples of org.apache.log4j.Category


        }
        else {
            StringTokenizer st = new StringTokenizer(categoryNames, ",");
            while (st.hasMoreTokens()) {
                String c = st.nextToken().trim();
                Category cat = Category.getInstance(c);
                cat.setPriority(logLevel);
            }  
        }
    }
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

   */
  public
  void testAdditivity3() {

    Category root = Category.getRoot();   
    Category a = Category.getInstance("a");
    Category ab = Category.getInstance("a.b");
    Category abc = Category.getInstance("a.b.c");
    Category x   = Category.getInstance("x");

    CountingAppender caRoot = new CountingAppender();
    CountingAppender caA = new CountingAppender();
    CountingAppender caABC = new CountingAppender();

View Full Code Here


  public
  void testDisable1() {
    CountingAppender caRoot = new CountingAppender();
    Category root = Category.getRoot();   
    root.addAppender(caRoot);

    BasicConfigurator.disableDebug();
    assertEquals(caRoot.counter, 0);    

    root.debug(MSG); assertEquals(caRoot.counter, 0)
    root.info(MSG); assertEquals(caRoot.counter, 1)
    root.log(Priority.WARN, MSG); assertEquals(caRoot.counter, 2)
    root.warn(MSG); assertEquals(caRoot.counter, 3)

    BasicConfigurator.disableInfo();
    root.debug(MSG); assertEquals(caRoot.counter, 3)
    root.info(MSG); assertEquals(caRoot.counter, 3)
    root.log(Priority.WARN, MSG); assertEquals(caRoot.counter, 4)
    root.error(MSG); assertEquals(caRoot.counter, 5)
    root.log(Priority.ERROR, MSG); assertEquals(caRoot.counter, 6)

    BasicConfigurator.disableAll();
    root.debug(MSG); assertEquals(caRoot.counter, 6)
    root.info(MSG); assertEquals(caRoot.counter, 6)
    root.log(Priority.WARN, MSG); assertEquals(caRoot.counter, 6)
    root.error(MSG); assertEquals(caRoot.counter, 6)
    root.log(Priority.FATAL, MSG); assertEquals(caRoot.counter, 6)
    root.log(Priority.FATAL, MSG); assertEquals(caRoot.counter, 6)

    BasicConfigurator.disable(Priority.FATAL);
    root.debug(MSG); assertEquals(caRoot.counter, 6)
    root.info(MSG); assertEquals(caRoot.counter, 6)
    root.log(Priority.WARN, MSG); assertEquals(caRoot.counter, 6)
    root.error(MSG); assertEquals(caRoot.counter, 6);
    root.log(Priority.ERROR, MSG); assertEquals(caRoot.counter, 6)
    root.log(Priority.FATAL, MSG); assertEquals(caRoot.counter, 6)
  }
View Full Code Here

  }


  public
  void testRB1() {
    Category root = Category.getRoot();
    root.setResourceBundle(rbUS);
    ResourceBundle t = root.getResourceBundle();
    assertSame(t, rbUS);

    Category x = Category.getInstance("x");
    Category x_y = Category.getInstance("x.y");
    Category x_y_z = Category.getInstance("x.y.z");

    t = x.getResourceBundle();     assertSame(t, rbUS);
    t = x_y.getResourceBundle();   assertSame(t, rbUS);
    t = x_y_z.getResourceBundle(); assertSame(t, rbUS);
  }
View Full Code Here

    t = x_y_z.getResourceBundle(); assertSame(t, rbUS);
  }

  public
  void testRB2() {
    Category root = Category.getRoot();
    root.setResourceBundle(rbUS);
    ResourceBundle t = root.getResourceBundle();
    assertSame(t, rbUS);

    Category x = Category.getInstance("x");
    Category x_y = Category.getInstance("x.y");
    Category x_y_z = Category.getInstance("x.y.z");

    x_y.setResourceBundle(rbFR);
    t = x.getResourceBundle();     assertSame(t, rbUS);
    t = x_y.getResourceBundle();   assertSame(t, rbFR);
    t = x_y_z.getResourceBundle(); assertSame(t, rbFR);   
  }
View Full Code Here

  }


  public
  void testRB3() {
    Category root = Category.getRoot();
    root.setResourceBundle(rbUS);
    ResourceBundle t = root.getResourceBundle();
    assertSame(t, rbUS);

    Category x = Category.getInstance("x");
    Category x_y = Category.getInstance("x.y");
    Category x_y_z = Category.getInstance("x.y.z");

    x_y.setResourceBundle(rbFR);
    x_y_z.setResourceBundle(rbCH);
    t = x.getResourceBundle();     assertSame(t, rbUS);
    t = x_y.getResourceBundle();   assertSame(t, rbFR);
    t = x_y_z.getResourceBundle(); assertSame(t, rbCH);   
  }
View Full Code Here

    t = x_y_z.getResourceBundle(); assertSame(t, rbCH);   
  }

  public
  void testExists() {
    Category a = Category.getInstance("a");
    Category a_b = Category.getInstance("a.b");
    Category a_b_c = Category.getInstance("a.b.c");
   
    Category t;
    t = Category.exists("xx");    assertNull(t);
    t = Category.exists("a");     assertSame(a, t);
    t = Category.exists("a.b");   assertSame(a_b, t);
    t = Category.exists("a.b.c"); assertSame(a_b_c, t);
  }
View Full Code Here

  }

  public
  void testHierarchy1() {
    Hierarchy h = new Hierarchy( new RootCategory(Priority.ERROR));
    Category a0 = h.getInstance("a");
    assertEquals("a", a0.getName());
    assertNull(a0.getPriority());
    assertSame(Priority.ERROR, a0.getChainedPriority());

    Category a1 = h.getInstance("a");
    assertSame(a0, a1);

   

   
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.