Exemplo n.º 1
0
  protected void sendExchange(PaxLoggingEvent paxLoggingEvent) {
    MDC.put(PaxLoggingConsumer.class.getName(), endpoint.getName());
    if (paxLoggingEvent.getProperties().containsKey(PaxLoggingConsumer.class.getName())) {
      return;
    }

    Exchange exchange = endpoint.createExchange();
    // TODO: populate exchange headers
    exchange.getIn().setBody(paxLoggingEvent);

    LOG.trace("PaxLogging {} is firing", endpoint.getName());
    try {
      getProcessor().process(exchange);
      // log exception if an exception occurred and was not handled
      if (exchange.getException() != null) {
        getExceptionHandler()
            .handleException("Error processing exchange", exchange, exchange.getException());
      }
    } catch (Exception e) {
      getExceptionHandler()
          .handleException("Error processing exchange", exchange, exchange.getException());
    }
  }
Exemplo n.º 2
0
  public void doAppend(final PaxLoggingEvent paxLoggingEvent) {
    try {

      // Only store TRACE events which have a trace-id.
      if ("TRACE".equals(paxLoggingEvent.getLevel().toString().toUpperCase())
          && !paxLoggingEvent.getProperties().containsKey("trace-id")) {
        return;
      }
      StringBuilder writer = new StringBuilder();
      writer.append("{ \"host\" : ");
      quote(name, writer);
      writer.append(",\n  \"timestamp\" : ");
      quote(formatDate(paxLoggingEvent.getTimeStamp()), writer);
      writer.append(",\n  \"level\" : ");
      quote(paxLoggingEvent.getLevel().toString(), writer);
      writer.append(",\n  \"logger\" : ");
      quote(paxLoggingEvent.getLoggerName(), writer);
      writer.append(",\n  \"thread\" : ");
      quote(paxLoggingEvent.getThreadName(), writer);
      writer.append(",\n  \"message\" : ");
      quote(paxLoggingEvent.getMessage(), writer);

      String[] throwable = paxLoggingEvent.getThrowableStrRep();
      if (throwable != null) {
        throwable = addMavenCoord(throwable);
        writer.append(",\n  \"exception\" : [");
        for (int i = 0; i < throwable.length; i++) {
          if (i != 0) writer.append(", ");
          quote(throwable[i], writer);
        }
        writer.append("]");
      }

      writer.append(",\n  \"properties\" : { ");
      boolean first = true;
      Map<String, String> properties = new HashMap<String, String>();
      Set<Map.Entry> set = paxLoggingEvent.getProperties().entrySet();
      for (Map.Entry entry : set) {
        Object key = entry.getKey();
        Object value = entry.getValue();
        if (key != null && value != null) {
          properties.put(key.toString(), value.toString());
        }
      }
      addMavenCoord(properties);

      for (Object key : properties.keySet()) {
        if (first) {
          first = false;
        } else {
          writer.append(", ");
        }
        quote(key.toString(), writer);
        writer.append(": ");
        quote(properties.get(key).toString(), writer);
      }
      writer.append(" }");
      writer.append("\n}");

      storage.store(type, paxLoggingEvent.getTimeStamp(), writer.toString());
    } catch (Exception e) {
      LOGGER.warn("Error appending log to storage", e);
    }
  }