Esempio n. 1
0
  @Test
  @SuppressWarnings("unchecked")
  public void getLoggerAppenders() {
    List<String> list =
        (List<String>)
            jmxClientTemplate.invoke(
                Log4jMBean.LOG4J_MBEAN_NAME,
                "getLoggerAppenders",
                new Class[] {String.class},
                new Object[] {"org.springside"});

    assertEquals(2, list.size());
    assertEquals("Console(parent)", list.get(0));
    assertEquals("RollingFile(parent)", list.get(1));

    list =
        (List<String>)
            jmxClientTemplate.invoke(
                Log4jMBean.LOG4J_MBEAN_NAME,
                "getLoggerAppenders",
                new Class[] {String.class},
                new Object[] {"DBLogExample"});

    assertEquals(2, list.size());
    assertEquals("Console", list.get(0));
    assertEquals("DBLog", list.get(1));
  }
Esempio n. 2
0
  @Test
  public void accessLoggerLevel() {
    String loggerName = "foo";
    String oldLevel = "WARN";
    String newLevel = "ERROR";

    // 判断原级别
    assertEquals(
        oldLevel,
        jmxClientTemplate.invoke(
            Log4jMBean.LOG4J_MBEAN_NAME,
            "getLoggerLevel",
            new Class[] {String.class},
            new Object[] {loggerName}));
    // 设定新级别
    jmxClientTemplate.invoke(
        Log4jMBean.LOG4J_MBEAN_NAME,
        "setLoggerLevel",
        new Class[] {String.class, String.class},
        new Object[] {loggerName, newLevel});
    assertEquals(newLevel, Logger.getLogger(loggerName).getEffectiveLevel().toString());
    // 恢复原级别
    jmxClientTemplate.invoke(
        Log4jMBean.LOG4J_MBEAN_NAME,
        "setLoggerLevel",
        new Class[] {String.class, String.class},
        new Object[] {loggerName, oldLevel});
  }