Exemple #1
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);
	}
  @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));
  }
Exemple #3
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());
   }
 }