@Override
 public String convert(ILoggingEvent event) {
   final Marker marker = event.getMarker();
   return marker == null
       ? (event.getLevel() == null ? "" : event.getLevel().toString())
       : marker.getName();
 }
 private void SysPrint(Marker marker, String msg, Object... obj) {
   if (obj != null) {
     Throwable t = null;
     StringBuffer s = new StringBuffer("[");
     s.append(marker.toString()).append("] ").append(msg);
     s.append(" args=[");
     boolean first = true;
     for (Object o : obj) {
       if (o instanceof Throwable) {
         t = (Throwable) o;
       } else {
         if (first) {
           s.append(o.toString());
           first = false;
         } else {
           s.append(", ").append(o.toString());
         }
       }
     }
     System.out.println(s.toString());
     if (t != null) {
       t.printStackTrace();
     }
   } else {
     System.out.println(msg);
   }
 }
Beispiel #3
0
	@Override
	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain filterChain) throws IOException, ServletException {
		fatalMarker.add(errorMarker);
		LOGGER.debug(fatalMarker, "filter {} has filtered", this.getClass().getName());
		filterChain.doFilter(req, res);
	}
Beispiel #4
0
 @Override
 public FilterReply decide(ILoggingEvent event) {
   Marker marker = event.getMarker();
   if (!isStarted()) return FilterReply.NEUTRAL;
   if (null == marker) return onMismatch;
   if (markerToMatch.contains(marker)) return onMatch;
   return onMismatch;
 }
  @Test
  public void testComposite() {
    String compositeMarkerName = COMPOSITE;
    Marker compositeMarker = MarkerFactory.getMarker(compositeMarkerName);
    compositeMarker.add(totoMarker);

    MarkerFilter mkt = new MarkerFilter();
    mkt.setMarker(TOTO);
    mkt.setOnMatch("ACCEPT");
    mkt.setOnMismatch("DENY");

    mkt.start();

    assertTrue(mkt.isStarted());
    assertEquals(FilterReply.DENY, mkt.decide(null, null, null, null, null, null));
    assertEquals(FilterReply.ACCEPT, mkt.decide(totoMarker, null, null, null, null, null));
    assertEquals(FilterReply.ACCEPT, mkt.decide(compositeMarker, null, null, null, null, null));
  }
Beispiel #6
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());
   }
 }
  @Test
  public void testHashCode() {
    Marker equalsTMarker = new TranslationMarker("translation.key");
    Marker otherTMarker = new TranslationMarker("translation.otherkey");
    Marker otherMarker = MarkerFactory.getMarker("name");

    Assert.assertEquals(equalsTMarker.hashCode(), this.marker.hashCode());
    Assert.assertFalse(this.marker.hashCode() == otherTMarker.hashCode());
    Assert.assertFalse(this.marker.hashCode() == otherMarker.hashCode());
  }