コード例 #1
0
  @Test
  public void testAppendLoggingEvent() throws SQLException {
    ILoggingEvent event = createLoggingEvent();

    appender.append(event);
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);

    Statement stmt = connectionSource.getConnection().createStatement();
    ResultSet rs = null;
    rs = stmt.executeQuery("SELECT * FROM logging_event");
    if (rs.next()) {
      assertEquals(event.getTimeStamp(), rs.getLong(DBAppender.TIMESTMP_INDEX));
      assertEquals(event.getFormattedMessage(), rs.getString(DBAppender.FORMATTED_MESSAGE_INDEX));
      assertEquals(event.getLoggerName(), rs.getString(DBAppender.LOGGER_NAME_INDEX));
      assertEquals(event.getLevel().toString(), rs.getString(DBAppender.LEVEL_STRING_INDEX));
      assertEquals(event.getThreadName(), rs.getString(DBAppender.THREAD_NAME_INDEX));
      assertEquals(
          DBHelper.computeReferenceMask(event), rs.getShort(DBAppender.REFERENCE_FLAG_INDEX));
      assertEquals(String.valueOf(diff), rs.getString(DBAppender.ARG0_INDEX));
      StackTraceElement callerData = event.getCallerData()[0];
      assertEquals(callerData.getFileName(), rs.getString(DBAppender.CALLER_FILENAME_INDEX));
      assertEquals(callerData.getClassName(), rs.getString(DBAppender.CALLER_CLASS_INDEX));
      assertEquals(callerData.getMethodName(), rs.getString(DBAppender.CALLER_METHOD_INDEX));
    } else {
      fail("No row was inserted in the database");
    }

    rs.close();
    stmt.close();
  }
コード例 #2
0
  public void process(ILoggingEvent event) {
    if (hold) {
      event.getThreadName(); // force "logback" to remember current thread
      events.add(event);
      if (event.getLevel().isGreaterOrEqual(Level.ERROR)) {
        hold = false;

        flushTraceLogs();

        events.clear();
      }
    } else {
      appender.doAppend(event);
    }
  }
コード例 #3
0
  @Override
  protected void append(ILoggingEvent p) {
    if (!enable || eventWriter == null || !eventWriter.isEnable()) {
      return;
    }

    Level logLevel = p.getLevel();
    if (logLevel.toInt() < minimumLevel) {
      return;
    }

    RecordEventSummary eventInfo = new RecordEventSummary(-1);

    eventInfo.setEventType(eventType);
    eventInfo.setThreadName(p.getThreadName());
    eventInfo.setEventDate(new Date(p.getTimeStamp()));
    eventInfo.setEventClassName(p.getLoggerName());
    eventInfo.setEventMethodName(logLevel.toString().toLowerCase());

    // use message instead of formattedMessage for header!!
    // => use "... {0} .. {1} .." to compress event summary encoding
    eventInfo.setEventMethodDetail(p.getMessage());

    if (!eventWriter.isEnable(eventInfo)) {
      return;
    }

    LogbackEventData eventData = new LogbackEventData();
    eventData.setLevel(eventInfo, logLevel.toString());
    eventData.setFormattedMessage(p.getFormattedMessage());
    eventData.setArgumentArray(p.getArgumentArray());

    if (p.getThrowableProxy() != null) {
      IThrowableProxy throwableProxy = p.getThrowableProxy();
      // throwableProxy.getClassName()
      // throwableProxy.getMessage()
      StackTraceElementProxy[] traceElts = throwableProxy.getStackTraceElementProxyArray();
      eventData.setStackTraceElements(traceElts);
    }

    Map<String, String> mdcPropertyMap = p.getMDCPropertyMap();
    if (mdcPropertyMap != null && !mdcPropertyMap.isEmpty()) {
      eventData.setMDCPropertyMap(mdcPropertyMap);
    }

    eventWriter.addEvent(eventInfo, eventData, null);
  }
コード例 #4
0
  /**
   * Converts the additional fields into proper GELF JSON
   *
   * @param map The map of additional fields
   * @param eventObject The Logging event that we are converting to GELF
   */
  private void additionalFields(Map<String, Object> map, ILoggingEvent eventObject) {

    if (useLoggerName) {
      map.put("_loggerName", eventObject.getLoggerName());
    }

    if (useMarker && eventHasMarker(eventObject)) {
      map.put("_marker", eventObject.getMarker().toString());
    }

    if (useThreadName) {
      map.put("_threadName", eventObject.getThreadName());
    }

    Map<String, String> mdc = eventObject.getMDCPropertyMap();

    if (mdc != null) {

      if (includeFullMDC) {
        for (Entry<String, String> e : mdc.entrySet()) {
          if (additionalFields.containsKey(e.getKey())) {
            map.put(additionalFields.get(e.getKey()), e.getValue());
          } else {
            map.put("_" + e.getKey(), e.getValue());
          }
        }
      } else {
        for (String key : additionalFields.keySet()) {
          String field = mdc.get(key);
          if (field != null) {
            map.put(additionalFields.get(key), field);
          }
        }
      }
    }
  }
コード例 #5
0
 public String convert(ILoggingEvent event) {
   return event.getThreadName();
 }