@Test
  public void append_basic() {
    MockLoggingChannel log = new MockLoggingChannel();
    KettleLogChannelAppender appender = new KettleLogChannelAppender(log);
    Logger testLogger = Logger.getLogger(getClass());
    testLogger.setLevel(Level.ALL);
    Layout layout = new Log4jKettleLayout();

    // ALL, INFO, and WARN messages should be interpreted as "basic" messages
    @SuppressWarnings("deprecation")
    LoggingEvent infoEvent =
        new LoggingEvent("org.test", testLogger, Priority.INFO, "Testing Info", null);
    @SuppressWarnings("deprecation")
    LoggingEvent warnEvent =
        new LoggingEvent("org.test", testLogger, Priority.WARN, "Testing Warning", null);
    @SuppressWarnings("deprecation")
    LoggingEvent allEvent =
        new LoggingEvent(
            "org.test", testLogger, Priority.toPriority(Priority.ALL_INT), "Testing All", null);
    appender.doAppend(infoEvent);
    appender.doAppend(warnEvent);
    appender.doAppend(allEvent);

    assertEquals(0, log.getDebugMessages().size());
    assertEquals(0, log.getDetailedMessages().size());
    assertEquals(0, log.getErrorMessages().size());
    assertEquals(0, log.getMinimalMessages().size());
    assertEquals(0, log.getRowLevelMessages().size());

    assertEquals(3, log.getBasicMessages().size());
    assertEquals(layout.format(infoEvent), log.getBasicMessages().get(0).getMessage());
    assertEquals(layout.format(warnEvent), log.getBasicMessages().get(1).getMessage());
    assertEquals(layout.format(allEvent), log.getBasicMessages().get(2).getMessage());
  }
 public void log(String str, int level, Object obj, Throwable t) {
   if (logger == null) {
     logger = org.apache.log4j.Logger.getLogger("NullLogger");
     logger.error("Logger was reset to null. Creating null logger");
   }
   if (logger != null) {
     logger.log(str, Priority.toPriority(level), obj, t);
   }
 }
  @Test
  public void append_off() {
    MockLoggingChannel log = new MockLoggingChannel();
    KettleLogChannelAppender appender = new KettleLogChannelAppender(log);
    Logger testLogger = Logger.getLogger(getClass());
    testLogger.setLevel(Level.ALL);

    // OFF logging events should be interpreted as "minimal" messages
    Layout layout = new Log4jKettleLayout();
    @SuppressWarnings("deprecation")
    LoggingEvent event =
        new LoggingEvent(
            "org.test", testLogger, Priority.toPriority(Level.OFF_INT), "off test!", null);

    appender.doAppend(event);
    assertEquals(0, log.getBasicMessages().size());
    assertEquals(0, log.getDetailedMessages().size());
    assertEquals(0, log.getErrorMessages().size());
    assertEquals(0, log.getRowLevelMessages().size());
    assertEquals(0, log.getDebugMessages().size());

    assertEquals(1, log.getMinimalMessages().size());
    assertEquals(layout.format(event), log.getMinimalMessages().get(0).getMessage());
  }
Пример #4
0
 public void publishEvent(Priority prio, String text) {
   synchronized (evts) {
     evts.add(new EventBufferElement(prio, text));
     if (triggerPrio != null && prio.isGreaterOrEqual(triggerPrio)) evts.notify();
   }
 }