當前位置: 首頁>>代碼示例>>Java>>正文


Java Filter類代碼示例

本文整理匯總了Java中org.apache.log4j.spi.Filter的典型用法代碼示例。如果您正苦於以下問題:Java Filter類的具體用法?Java Filter怎麽用?Java Filter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Filter類屬於org.apache.log4j.spi包,在下文中一共展示了Filter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decide

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
@Test
public void decide() {

	assertNotNull(mdcFilter);

	mdcFilter.setExpression("MessageId!=null || LoggedBy!=null");
	mdcFilter.setKeys("LoggedBy,MessageId");

	final LoggingEvent event = new LoggingEvent("", LOG, LOG.getLevel(),
			"MessageId=123", null);

	MDC.put("LoggedBy", "abc");
	MDC.put("fff", "abc");

	final int ret = mdcFilter.decide(event);
	LOG.info("decide: " + ret);
	assertTrue(ret == Filter.NEUTRAL);
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:19,代碼來源:MDCFilterTest.java

示例2: doAppend

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
/**
 * 覆寫doAppend, 去掉closed的log日誌
 * @param event
 */
@Override
public synchronized void doAppend(LoggingEvent event) {
    if (closed) {
        return;
    }

    if (!isAsSevereAsThreshold(event.getLevel())) {
        return;
    }

    Filter f = this.headFilter;

    FILTER_LOOP:
    while(f != null) {
        switch(f.decide(event)) {
            case Filter.DENY: return;
            case Filter.ACCEPT: break FILTER_LOOP;
            case Filter.NEUTRAL: f = f.getNext();
        }
    }

    this.append(event);
}
 
開發者ID:JThink,項目名稱:SkyEye,代碼行數:28,代碼來源:KafkaAppender.java

示例3: init

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
public static void init(CmpSqlResultsConfig cmpSqlResultsConfig) {
    log.debug("Initializing logger / printer ...");
    ConsoleAppender consoleAppender = (ConsoleAppender) Logger.getRootLogger().getAppender("stdout");
    if (cmpSqlResultsConfig.getLogger() != null && cmpSqlResultsConfig.getLogger().getLogLevel() !=
            null && !cmpSqlResultsConfig.getLogger().getLogLevel().isEmpty()) {
        Logger.getRootLogger().setLevel(Level.toLevel(cmpSqlResultsConfig.getLogger().getLogLevel()));
    }
    if (cmpSqlResultsConfig.getLogger().isTeamcityLogsEnabled()) {
        consoleAppender.setLayout(new PatternLayout("%m%n"));
    }
    consoleAppender.addFilter(new Filter() {
        @Override
        public int decide(LoggingEvent loggingEvent) {
            if(loggingEvent.getMessage() instanceof String == false) return ACCEPT;
            boolean isTCMsg = ((String) loggingEvent.getMessage()).contains(TCMessages.TC);
            // before threads (and buffering messages for TC) we allowed "common" logs
            // boolean isNotTCMsg = ((String) loggingEvent.getMessage()).contains(TCMessages.NOT_TC);
            if (cmpSqlResultsConfig.getLogger().isTeamcityLogsEnabled()) {
                return isTCMsg ? ACCEPT : DENY;
                // return isNotTCMsg ? DENY : ACCEPT;
            } else {
                return isTCMsg ? DENY : ACCEPT;
            }
        }
    });
}
 
開發者ID:ObjectivityLtd,項目名稱:DBTestCompare,代碼行數:27,代碼來源:Printer.java

示例4: removeFilter

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
private static void removeFilter(final Appender appender, final Filter filter) {
  Filter _filter = appender.getFilter();
  boolean _equals = Objects.equal(_filter, filter);
  if (_equals) {
    appender.clearFilters();
    appender.addFilter(filter.getNext());
  } else {
    for (Filter current = appender.getFilter(); (current != null); current = current.getNext()) {
      Filter _next = current.getNext();
      boolean _equals_1 = Objects.equal(_next, filter);
      if (_equals_1) {
        current.setNext(filter.getNext());
        return;
      }
    }
  }
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:18,代碼來源:LoggingTester.java

示例5: doAppend

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
/**
  * This method performs threshold checks and invokes filters before
  * delegating actual logging to the subclasses specific {@link
  * AppenderSkeleton#append} method.
  * */
public
synchronized 
void doAppend(LoggingEvent event) {
  if(closed) {
    LogLog.error("Attempted to append to closed appender named ["+name+"].");
    return;
  }
  
  if(!isAsSevereAsThreshold(event.getLevel())) {
    return;
  }

  Filter f = this.headFilter;
  
  FILTER_LOOP:
  while(f != null) {
    switch(f.decide(event)) {
    case Filter.DENY: return;
    case Filter.ACCEPT: break FILTER_LOOP;
    case Filter.NEUTRAL: f = f.getNext();
    }
  }
  
  this.append(event);    
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:31,代碼來源:AppenderSkeleton.java

示例6: decide

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
/**
   Return the decision of this filter.

   Returns {@link Filter#NEUTRAL} if the <b>LevelToMatch</b> option
   is not set or if there is not match.  Otherwise, if there is a
   match, then the returned decision is {@link Filter#ACCEPT} if the
   <b>AcceptOnMatch</b> property is set to <code>true</code>. The
   returned decision is {@link Filter#DENY} if the
   <b>AcceptOnMatch</b> property is set to false.

*/
public
int decide(LoggingEvent event) {
  if(this.levelToMatch == null) {
    return Filter.NEUTRAL;
  }
  
  boolean matchOccured = false;
  if(this.levelToMatch.equals(event.getLevel())) {
    matchOccured = true;
  } 

  if(matchOccured) {  
    if(this.acceptOnMatch)
 return Filter.ACCEPT;
    else
 return Filter.DENY;
  } else {
    return Filter.NEUTRAL;
  }
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:32,代碼來源:LevelMatchFilter.java

示例7: decide

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
/**
    Returns {@link Filter#NEUTRAL} is there is no string match.
  */
 public
 int decide(LoggingEvent event) {
   String msg = event.getRenderedMessage();

   if(msg == null ||  stringToMatch == null)
     return Filter.NEUTRAL;
   

   if( msg.indexOf(stringToMatch) == -1 ) {
     return Filter.NEUTRAL;
   } else { // we've got a match
     if(acceptOnMatch) {
return Filter.ACCEPT;
     } else {
return Filter.DENY;
     }
   }
 }
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:22,代碼來源:StringMatchFilter.java

示例8: configureLogger

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
private synchronized void configureLogger() {
  org.apache.log4j.Logger npmLogger = org.apache.log4j.Logger.getLogger(
      "com.github.eirslett.maven.plugins.frontend.lib.DefaultYarnRunner");
  Enumeration appenders = org.apache.log4j.Logger.getRootLogger().getAllAppenders();

  if (appenders != null) {
    while (appenders.hasMoreElements()) {
      Appender appender = (Appender) appenders.nextElement();
      appender.addFilter(new Filter() {

        @Override
        public int decide(LoggingEvent loggingEvent) {
          if (loggingEvent.getLoggerName().contains("DefaultYarnRunner")) {
            return DENY;
          } else {
            return NEUTRAL;
          }
        }
      });
    }
  }
  npmLogger.addAppender(new WriterAppender(
      new PatternLayout("%m%n"),
      out
  ));
}
 
開發者ID:apache,項目名稱:zeppelin,代碼行數:27,代碼來源:HeliumBundleFactory.java

示例9: setupBeforeClass

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
@BeforeClass
public static void setupBeforeClass() throws Exception {
	Logger xenqtt = Logger.getLogger("xenqtt");
	assertNotNull(xenqtt);

	Appender console = Logger.getRootLogger().getAppender("console");
	assertNotNull(console);

	console.addFilter(new Filter() {
		@Override
		public int decide(LoggingEvent event) {
			entries.add(event.getRenderedMessage());

			ThrowableInformation info = event.getThrowableInformation();
			if (info != null) {
				Throwable t = info.getThrowable();
				if (t != null) {
					entries.add(t.getMessage());
				}
			}

			return Filter.ACCEPT;
		}
	});
}
 
開發者ID:TwoGuysFromKabul,項目名稱:xenqtt,代碼行數:26,代碼來源:LogTest.java

示例10: configureConsoleAppender

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
private void configureConsoleAppender(Properties properties, String consoleAppenderName) {
		Appender consoleAppender = Logger.getRootLogger().getAppender(consoleAppenderName);
		if (consoleAppender == null)
			return;
		
		final Level level = Level.toLevel(properties.getProperty(consoleAppenderName + ".level"), Level.ERROR);
		
		consoleAppender.addFilter(new Filter() {
			@Override
			public int decide(LoggingEvent evt) {
//				if (evt.getLevel().isGreaterOrEqual(level))
					return ACCEPT;
//				return DENY;
			}
		});
		
		trace.info("Setting console appender logging level to '" + level + "'");
	}
 
開發者ID:nasa,項目名稱:OpenSPIFe,代碼行數:19,代碼來源:EnsembleLoggingConfigurator.java

示例11: doAppend

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
/**
  * This method performs threshold checks and invokes filters before
  * delegating actual logging to the subclasses specific {@link
  * AppenderSkeleton#append} method.
  * */
public
synchronized 
void doAppend(LoggingEvent event) {
  if(closed) {
    LogLog.error("Attempted to append to closed appender named ["+name+"].");
    return;
  }
  
  if(!isAsSevereAsThreshold(event.getLevel())) {
    return;
  }

  Filter f = this.headFilter;
  
  FILTER_LOOP:
  while(f != null) {
    switch(f.decide(event)) {
    case Filter.DENY: return;
    case Filter.ACCEPT: break FILTER_LOOP;
    case Filter.NEUTRAL: f = f.next;
    }
  }
  
  this.append(event);    
}
 
開發者ID:nologic,項目名稱:nabs,代碼行數:31,代碼來源:AppenderSkeleton.java

示例12: initializeLogging

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
protected void initializeLogging(JobExecutionContext jobExecutionContext) {
    String jobName = jobExecutionContext.getJobDetail().getName();
    try {
        String nestedDiagnosticContext = getNestedDiagnosticContext(jobName);
        String logFilename = getLogFileName(nestedDiagnosticContext);
        System.out.println("Log filename=" + logFilename);
        Job job = (Job) jobExecutionContext.getJobInstance();
        Logger rootLogger = Logger.getRootLogger();
        Appender appender = rootLogger.getAppender("LogFile");
        Layout layout = getLayout(appender);
        Appender newAppender = new FileAppender(layout, logFilename);
        Filter newFilter = new NDCFilter(nestedDiagnosticContext);
        newAppender.addFilter(newFilter);
        job.setNdcAppender(newAppender);
        rootLogger.addAppender(newAppender);
        NDC.push(nestedDiagnosticContext);
    }
    catch (IOException e) {
        LOG.warn("Could not initialize special custom logging for job: " + jobName, e);
    }
}
 
開發者ID:VU-libtech,項目名稱:OLE-INST,代碼行數:22,代碼來源:JobListener.java

示例13: decide

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
public int decide(LoggingEvent event) {
	if (levelMin == null || event.getLevel().isGreaterOrEqual(levelMin))
		return Filter.NEUTRAL;

	String tn = event.getThreadName();

	if (tn == null || regex == null)
		return Filter.NEUTRAL;

	if (tn.matches(regex)) {
		if (getAcceptOnMatch()) {
			return Filter.ACCEPT;
		} else {
			return Filter.DENY;
		}
	} else {
		return Filter.NEUTRAL;
	}
}
 
開發者ID:ibissource,項目名稱:iaf,代碼行數:20,代碼來源:IbisThreadFilter.java

示例14: JTextPaneAppender

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
/**
 * Constructor
 * 
 * @param aLayout
 * @param aName
 * @param aFilterArray
 * @param aTextPane
 * @param maxLines
 */
public JTextPaneAppender(Layout aLayout, String aName,
		Filter[] aFilterArray, JTextPane aTextPane, int maxLines) {
	this();
	this.layout = aLayout;
	this.name = aName;
	this.maxLines = maxLines;
	myTextPane = aTextPane;

	if (aFilterArray != null) {
		for (int i = 0; i < aFilterArray.length; i++) {
			if (aFilterArray[i] != null) {
				addFilter(aFilterArray[i]);
			} // if aFilterArray[i] != null]
		} // for i

	} // if aFilterArray != null

	createAttributes();
}
 
開發者ID:EclipseETS,項目名稱:eclipse-telemetry,代碼行數:29,代碼來源:JTextPaneAppender.java

示例15: decide

import org.apache.log4j.spi.Filter; //導入依賴的package包/類
/**
 *
 * @param event 需進行裁決的loggingEvent
 * @return 裁決結果
 */
public int decide(LoggingEvent event) {
    if (tokenBucket == null) {
        tokenBucket = new TokenBucket(refillAmount, refillInterval,
                maxBurst);
    }

    return tokenBucket.consume() ? Filter.DENY : Filter.NEUTRAL;
}
 
開發者ID:baidu,項目名稱:openrasp,代碼行數:14,代碼來源:BurstFilter.java


注:本文中的org.apache.log4j.spi.Filter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。