예제 #1
0
파일: Benchmark.java 프로젝트: huxi/lilith
  public void javaUtilXmlCompressed(List<EventWrapper<LoggingEvent>> loggingEvents) {
    boolean compressed = true;
    Encoder<LoggingEvent> encoder =
        new XmlEncoder<LoggingEvent>(compressed, LoggingEvent.Level.class);
    Decoder<LoggingEvent> decoder = new XmlDecoder<LoggingEvent>(compressed);
    List<byte[]> collectedBytes = new ArrayList<byte[]>(loggingEvents.size());
    long byteCounter = 0;
    startTest();
    for (EventWrapper<LoggingEvent> current : loggingEvents) {
      byte[] bytes = encoder.encode(current.getEvent());
      byteCounter += bytes.length;
      collectedBytes.add(bytes);
    }
    stopTest("javaBeansXmlCompressed", "encode", byteCounter, loggingEvents.size());
    if (logger.isDebugEnabled()) logger.debug("byteCounter: {}", byteCounter);

    long dummy = 0;
    startTest();
    for (byte[] current : collectedBytes) {
      LoggingEvent event = decoder.decode(current);
      dummy += event.hashCode();
    }
    stopTest("javaBeansXmlCompressed", "decode", byteCounter, loggingEvents.size());
    if (logger.isDebugEnabled()) logger.debug("Dummy: {}", dummy);
  }
  public String toString(Object object) {
    if (object instanceof EventWrapper) {
      EventWrapper wrapper = (EventWrapper) object;
      if (wrapper.getEvent() != null) {
        Object eventObj = wrapper.getEvent();
        if (eventObj instanceof LoggingEvent) {
          LoggingEvent loggingEvent = (LoggingEvent) eventObj;
          return loggingEvent.getLogger();
        }
      }
    }

    return null;
  }
예제 #3
0
  public boolean isTrue(Object value) {
    if (searchString == null) {
      return false;
    }
    if (searchString.length() == 0) {
      return true;
    }
    if (value instanceof EventWrapper) {
      EventWrapper wrapper = (EventWrapper) value;
      Object eventObj = wrapper.getEvent();
      if (eventObj instanceof LoggingEvent) {
        LoggingEvent event = (LoggingEvent) eventObj;

        String logger = event.getLogger();

        return logger != null && logger.equals(searchString);
      }
    }
    return false;
  }
예제 #4
0
  @Override
  public boolean isTrue(Object element) {
    if (key == null) {
      return false;
    }
    if (element instanceof EventWrapper) {
      EventWrapper wrapper = (EventWrapper) element;
      Object eventObj = wrapper.getEvent();
      if (eventObj instanceof LoggingEvent) {
        LoggingEvent event = (LoggingEvent) eventObj;

        Map<String, String> mdc = event.getMdc();
        if (mdc == null || mdc.isEmpty()) {
          return false;
        }

        String actualValue = mdc.get(key);
        //noinspection StringEquality
        return actualValue == value || value != null && value.equals(actualValue);
      }
    }
    return false;
  }
예제 #5
0
파일: Benchmark.java 프로젝트: huxi/lilith
  public void protobufUncompressed(List<EventWrapper<LoggingEvent>> loggingEvents) {
    boolean compressed = false;
    Encoder<LoggingEvent> encoder = new LoggingEventProtobufEncoder(compressed);
    Decoder<LoggingEvent> decoder = new LoggingEventProtobufDecoder(compressed);
    List<byte[]> collectedBytes = new ArrayList<byte[]>(loggingEvents.size());
    long byteCounter = 0;
    startTest();
    for (EventWrapper<LoggingEvent> current : loggingEvents) {
      byte[] bytes = encoder.encode(current.getEvent());
      byteCounter += bytes.length;
      collectedBytes.add(bytes);
    }
    stopTest("protobufUncompressed", "encode", byteCounter, loggingEvents.size());
    if (logger.isDebugEnabled()) logger.debug("byteCounter: {}", byteCounter);

    long dummy = 0;
    startTest();
    for (byte[] current : collectedBytes) {
      LoggingEvent event = decoder.decode(current);
      dummy += event.hashCode();
    }
    stopTest("protobufUncompressed", "decode", byteCounter, loggingEvents.size());
    if (logger.isDebugEnabled()) logger.debug("Dummy: {}", dummy);
  }
예제 #6
0
파일: Benchmark.java 프로젝트: huxi/lilith
  private static LoggingEvent createLoggingEvent(int counter) {

    LoggingEvent result = new LoggingEvent();
    result.setMessage(
        new Message(
            "messagePattern-" + counter + ": {} {}",
            new String[] {"param1-" + counter, "param2-" + counter}));
    result.setLevel(LoggingEvent.Level.INFO);
    result.setLogger("logger-" + counter);
    result.setMarker(new Marker("marker-" + counter));
    Map<String, String> mdc = new HashMap<String, String>();
    mdc.put("key-" + counter, "value-" + counter);
    result.setMdc(mdc);
    result.setNdc(
        new Message[] {
          new Message(
              "ndcMessagePattern-" + counter + ": {} {}",
              new String[] {"ndcParam1-" + counter, "ndcParam2-" + counter})
        });

    result.setThreadInfo(new ThreadInfo(null, "threadName-" + counter, null, null));
    ExtendedStackTraceElement[] originalCallStack = createCallStack();
    ExtendedStackTraceElement[] callStack =
        new ExtendedStackTraceElement[originalCallStack.length * 5];
    for (int i = 0; i < callStack.length; i++) {
      ExtendedStackTraceElement original = originalCallStack[i % originalCallStack.length];
      ExtendedStackTraceElement actual = new ExtendedStackTraceElement();
      if (original.getClassName() != null) {
        actual.setClassName(original.getClassName() + i);
      }
      if (original.getFileName() != null) {
        actual.setFileName(original.getFileName() + i);
      }
      if (original.getMethodName() != null) {
        actual.setMethodName(original.getMethodName() + i);
      }
      if (original.getCodeLocation() != null) {
        actual.setCodeLocation(original.getCodeLocation() + i);
      }
      if (original.getVersion() != null) {
        actual.setVersion(original.getVersion() + i);
      }
      actual.setLineNumber(original.getLineNumber());
      actual.setExact(original.isExact());

      callStack[i] = actual;
    }
    result.setCallStack(callStack);
    ThrowableInfo throwableInfo = createThrowableInfo();
    result.setThrowable(throwableInfo);
    result.setTimeStamp(1234567890000L);
    return result;
  }