示例#1
0
 private String getLogMessage(Event e) {
   StringBuilder builder = new StringBuilder("|");
   builder.append(e.getMessage());
   builder.append('|');
   builder.append(e.getMessageCode());
   builder.append("[");
   boolean first = true;
   for (String sub : e.getSubstitutions()) {
     if (!first) {
       builder.append(':');
     }
     builder.append(sub);
     first = false;
   }
   builder.append("]:[");
   first = true;
   for (String marker : e.getMarkers()) {
     if (!first) {
       builder.append(", ");
     }
     builder.append(marker);
     first = false;
   }
   builder.append(']');
   return builder.toString();
 }
示例#2
0
 @Override
 public void log(Event e) {
   Logger factory = LoggerFactory.getLogger(join(":", e.getContextNames()));
   MDC.setContextMap(e.getData());
   String[] markers = e.getMarkers();
   Marker marker = null;
   if (markers.length > 0) {
     marker = MarkerFactory.getDetachedMarker(markers[0]);
     for (int i = 1; i < markers.length; i++) {
       marker.add(MarkerFactory.getMarker(markers[i]));
     }
   }
   String logMessage = getLogMessage(e);
   Throwable[] errors = e.getErrors();
   Throwable firstError = errors.length > 0 ? errors[0] : null;
   switch (e.getSeverity()) {
     case INFO:
       factory.info(marker, logMessage, firstError);
       break;
     case WARN:
       factory.warn(marker, logMessage, firstError);
       break;
     case ERROR:
       factory.error(marker, logMessage, firstError);
       break;
     case DEBUG:
       factory.debug(marker, logMessage, firstError);
       break;
     case TRACE:
       factory.trace(marker, logMessage, firstError);
       break;
     case FATAL:
       factory.error(marker, logMessage, firstError);
       break;
     default:
       throw new RuntimeException("Unrecognized severity level: " + e.getSeverity().toString());
   }
 }