Java Code Examples for org.apache.log4j.spi.Filter

The following are top voted examples for showing how to use org.apache.log4j.spi.Filter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: xenqtt   File: LogTest.java   Source Code and License 7 votes vote down vote up
@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;
		}
	});
}
 
Example 2
Project: jaffa-framework   File: MDCFilterTest.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 3
Project: SkyEye   File: KafkaAppender.java   Source Code and License 6 votes vote down vote up
/**
 * 覆写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);
}
 
Example 4
Project: DBTestCompare   File: Printer.java   Source Code and License 6 votes vote down vote up
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;
            }
        }
    });
}
 
Example 5
Project: xtext-core   File: LoggingTester.java   Source Code and License 6 votes vote down vote up
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;
      }
    }
  }
}
 
Example 6
Project: cacheonix-core   File: AppenderSkeleton.java   Source Code and License 6 votes vote down vote up
/**
  * 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);    
}
 
Example 7
Project: cacheonix-core   File: LevelMatchFilter.java   Source Code and License 6 votes vote down vote up
/**
   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;
  }
}
 
Example 8
Project: cacheonix-core   File: StringMatchFilter.java   Source Code and License 6 votes vote down vote up
/**
    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;
     }
   }
 }
 
Example 9
Project: zeppelin   File: HeliumBundleFactory.java   Source Code and License 6 votes vote down vote up
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
  ));
}
 
Example 10
Project: daq-eclipse   File: AppenderSkeleton.java   Source Code and License 6 votes vote down vote up
/**
  * 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);    
}
 
Example 11
Project: daq-eclipse   File: LevelMatchFilter.java   Source Code and License 6 votes vote down vote up
/**
   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;
  }
}
 
Example 12
Project: daq-eclipse   File: StringMatchFilter.java   Source Code and License 6 votes vote down vote up
/**
    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;
     }
   }
 }
 
Example 13
Project: OpenSPIFe   File: EnsembleLoggingConfigurator.java   Source Code and License 6 votes vote down vote up
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 + "'");
	}
 
Example 14
Project: nabs   File: AppenderSkeleton.java   Source Code and License 6 votes vote down vote up
/**
  * 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);    
}
 
Example 15
Project: nabs   File: LevelMatchFilter.java   Source Code and License 6 votes vote down vote up
/**
   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;
  }
}
 
Example 16
Project: nabs   File: StringMatchFilter.java   Source Code and License 6 votes vote down vote up
/**
    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;
     }
   }
 }
 
Example 17
Project: OLE-INST   File: JobListener.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 18
Project: iaf   File: IbisThreadFilter.java   Source Code and License 6 votes vote down vote up
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;
	}
}
 
Example 19
Project: eclipse-telemetry   File: JTextPaneAppender.java   Source Code and License 6 votes vote down vote up
/**
 * 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();
}
 
Example 20
Project: openrasp   File: BurstFilter.java   Source Code and License 5 votes vote down vote up
/**
 *
 * @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;
}
 
Example 21
Project: reactor   File: AbstractCaseRunner.java   Source Code and License 5 votes vote down vote up
Path addLog4jFileAppender(final Path path) throws IOException {
    org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();

    String pattern = "%d{HH:mm:ss.SSS} %-5p %t %C{1}.%M:%L - %m%n";
    final String threadName = Thread.currentThread().getName();

    class ThreadFilter extends Filter {
        @Override
        public int decide(LoggingEvent event) {
            if (event.getThreadName().startsWith(threadName)) {
                return Filter.ACCEPT;
            }
            return Filter.DENY;
        }
    }

    FileAppender fa = new FileAppender(new PatternLayout(pattern), path.toFile().getAbsolutePath());
    fa.addFilter(new ThreadFilter());
    fa.setThreshold(sysConfig.getCaseLogLevel());
    fa.setImmediateFlush(true);
    fa.setAppend(true);
    fa.setName(path.toFile().getAbsolutePath());

    fa.activateOptions();
    rootLogger.addAppender(fa);

    return path;
}
 
Example 22
Project: xtext-core   File: LoggingTester.java   Source Code and License 5 votes vote down vote up
@Override
public int decide(final LoggingEvent event) {
  int _xifexpression = (int) 0;
  String _loggerName = event.getLoggerName();
  String _name = this.source.getName();
  boolean _equals = Objects.equal(_loggerName, _name);
  if (_equals) {
    _xifexpression = Filter.DENY;
  } else {
    _xifexpression = Filter.NEUTRAL;
  }
  return _xifexpression;
}
 
Example 23
Project: cacheonix-core   File: AppenderSkeleton.java   Source Code and License 5 votes vote down vote up
/**
   Add a filter to end of the filter list.

   @since 0.9.0
 */
public
void addFilter(Filter newFilter) {
  if(headFilter == null) {
    headFilter = tailFilter = newFilter;
  } else {
    tailFilter.setNext(newFilter);
    tailFilter = newFilter;    
  }
}
 
Example 24
Project: cacheonix-core   File: LevelRangeFilter.java   Source Code and License 5 votes vote down vote up
/**
   Return the decision of this filter.
 */
public
int decide(LoggingEvent event) {
  if(this.levelMin != null) {
    if (event.getLevel().isGreaterOrEqual(levelMin) == false) {
      // level of event is less than minimum
      return Filter.DENY;
    }
  }

  if(this.levelMax != null) {
    if (event.getLevel().toInt() > levelMax.toInt()) {
      // level of event is greater than maximum
      // Alas, there is no Level.isGreater method. and using
      // a combo of isGreaterOrEqual && !Equal seems worse than
      // checking the int values of the level objects..
      return Filter.DENY;
    }
  }

  if (acceptOnMatch) {
    // this filter set up to bypass later filters and always return
    // accept if level in range
    return Filter.ACCEPT;
  }
  else {
    // event is ok for this filter; allow later filters to have a look..
    return Filter.NEUTRAL;
  }
}
 
Example 25
Project: cacheonix-core   File: DOMConfigurator.java   Source Code and License 5 votes vote down vote up
/**
    Used internally to parse a filter element.
  */
 protected
 void parseFilters(Element element, Appender appender) {
   String clazz = subst(element.getAttribute(CLASS_ATTR));
   Filter filter = (Filter) OptionConverter.instantiateByClassName(clazz,
                                               Filter.class, null);
   
   if(filter != null) {
     PropertySetter propSetter = new PropertySetter(filter);
     NodeList children = element.getChildNodes();
     final int length 	= children.getLength();

     for (int loop = 0; loop < length; loop++) {
Node currentNode = children.item(loop);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
  Element currentElement = (Element) currentNode;
  String tagName = currentElement.getTagName();
  if(tagName.equals(PARAM_TAG)) {
           setParameter(currentElement, propSetter);
  } else {
           quietParseUnrecognizedElement(filter, currentElement, props);
     }
}
     }
     propSetter.activate();
     LogLog.debug("Adding filter of type ["+filter.getClass()
	   +"] to appender named ["+appender.getName()+"].");
     appender.addFilter(filter);
   }    
 }
 
Example 26
Project: log4j-s3-search   File: Log4jAppender.java   Source Code and License 5 votes vote down vote up
void initFilters() {
    addFilter(new Filter() {
        @Override
        public int decide(LoggingEvent event) {
            // To prevent infinite looping, we filter out events from
            // the publishing thread
            int decision = Filter.NEUTRAL;
            if (LoggingEventCache.PUBLISH_THREAD_NAME.equals(event.getThreadName())) {
                decision = Filter.DENY;
            }
            return decision;
        }});
}
 
Example 27
Project: daq-eclipse   File: AppenderSkeleton.java   Source Code and License 5 votes vote down vote up
/**
   Add a filter to end of the filter list.

   @since 0.9.0
 */
public
void addFilter(Filter newFilter) {
  if(headFilter == null) {
    headFilter = tailFilter = newFilter;
  } else {
    tailFilter.setNext(newFilter);
    tailFilter = newFilter;    
  }
}
 
Example 28
Project: daq-eclipse   File: LevelRangeFilter.java   Source Code and License 5 votes vote down vote up
/**
   Return the decision of this filter.
 */
public
int decide(LoggingEvent event) {
  if(this.levelMin != null) {
    if (event.getLevel().isGreaterOrEqual(levelMin) == false) {
      // level of event is less than minimum
      return Filter.DENY;
    }
  }

  if(this.levelMax != null) {
    if (event.getLevel().toInt() > levelMax.toInt()) {
      // level of event is greater than maximum
      // Alas, there is no Level.isGreater method. and using
      // a combo of isGreaterOrEqual && !Equal seems worse than
      // checking the int values of the level objects..
      return Filter.DENY;
    }
  }

  if (acceptOnMatch) {
    // this filter set up to bypass later filters and always return
    // accept if level in range
    return Filter.ACCEPT;
  }
  else {
    // event is ok for this filter; allow later filters to have a look..
    return Filter.NEUTRAL;
  }
}
 
Example 29
Project: daq-eclipse   File: DOMConfigurator.java   Source Code and License 5 votes vote down vote up
/**
    Used internally to parse a filter element.
  */
 protected
 void parseFilters(Element element, Appender appender) {
   String clazz = subst(element.getAttribute(CLASS_ATTR));
   Filter filter = (Filter) OptionConverter.instantiateByClassName(clazz,
                                               Filter.class, null);
   
   if(filter != null) {
     PropertySetter propSetter = new PropertySetter(filter);
     NodeList children = element.getChildNodes();
     final int length 	= children.getLength();

     for (int loop = 0; loop < length; loop++) {
Node currentNode = children.item(loop);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
  Element currentElement = (Element) currentNode;
  String tagName = currentElement.getTagName();
  if(tagName.equals(PARAM_TAG)) {
           setParameter(currentElement, propSetter);
  } else {
           quietParseUnrecognizedElement(filter, currentElement, props);
     }
}
     }
     propSetter.activate();
     LogLog.debug("Adding filter of type ["+filter.getClass()
	   +"] to appender named ["+appender.getName()+"].");
     appender.addFilter(filter);
   }    
 }
 
Example 30
Project: nabs   File: AppenderSkeleton.java   Source Code and License 5 votes vote down vote up
/**
   Add a filter to end of the filter list.

   @since 0.9.0
 */
public
void addFilter(Filter newFilter) {
  if(headFilter == null) {
    headFilter = tailFilter = newFilter;
  } else {
    tailFilter.next = newFilter;
    tailFilter = newFilter;    
  }
}
 
Example 31
Project: nabs   File: LevelRangeFilter.java   Source Code and License 5 votes vote down vote up
/**
   Return the decision of this filter.
 */
public
int decide(LoggingEvent event) {
  if(this.levelMin != null) {
    if (event.getLevel().isGreaterOrEqual(levelMin) == false) {
      // level of event is less than minimum
      return Filter.DENY;
    }
  }

  if(this.levelMax != null) {
    if (event.getLevel().toInt() > levelMax.toInt()) {
      // level of event is greater than maximum
      // Alas, there is no Level.isGreater method. and using
      // a combo of isGreaterOrEqual && !Equal seems worse than
      // checking the int values of the level objects..
      return Filter.DENY;
    }
  }

  if (acceptOnMatch) {
    // this filter set up to bypass later filters and always return
    // accept if level in range
    return Filter.ACCEPT;
  }
  else {
    // event is ok for this filter; allow later filters to have a look..
    return Filter.NEUTRAL;
  }
}
 
Example 32
Project: JECommons   File: DriverLoggerFactory.java   Source Code and License 5 votes vote down vote up
@Override
        public int decide(LoggingEvent le) {
            String mdc = (String) le.getMDC(KEY);
//        System.out.println("MDC: " + mdc);
//        System.out.println("key: " + _value);
            if (mdc.equals(_value)) {
                return Filter.ACCEPT;
            } else {
                return Filter.DENY;
            }
//        return Filter.ACCEPT;
        }
 
Example 33
Project: eterna   File: Log4jAppender.java   Source Code and License 5 votes vote down vote up
public void addFilter(Filter filter)
{
	if (this.filter != null)
	{
		this.filter = filter;
	}
}
 
Example 34
Project: LogManager   File: TestLog4j.java   Source Code and License 5 votes vote down vote up
public int decide(LoggingEvent event) {
    this.msg = (String) event.getMessage();
    if (event.getThrowableInformation() != null && event.getThrowableInformation().getThrowable() != null) {
        this.thrownMsg = event.getThrowableInformation().getThrowable().getMessage();
    }
    return Filter.NEUTRAL;
}
 
Example 35
Project: logging   File: EmptyMessageFilter.java   Source Code and License 5 votes vote down vote up
@Override
public int decide(LoggingEvent event) {
	if(event.getMessage() instanceof String){
		if(StringUtils.isEmpty((String)event.getMessage())){
			return Filter.DENY;
		}
	}
	return Filter.NEUTRAL;
}
 
Example 36
Project: JServer   File: RemoteRmiClientProxy.java   Source Code and License 5 votes vote down vote up
public void addAppenderFilter(String loggerName, Filter filter) throws RemoteException
{
   synchronized(this.appenders)
   {
      RmiAppender rmiAppender = (RmiAppender)this.appenders.get(loggerName);
      
      if( rmiAppender != null )
      {
         rmiAppender.addFilter(filter);
      }
   }
}
 
Example 37
Project: JServer   File: RmiClient.java   Source Code and License 5 votes vote down vote up
/**
 * 
 * @param loggerName
 * @param filter
 * @throws RemoteException
 */
public void addAppenderFilter(String loggerName, Filter filter) throws RemoteException
{
   if( this.currentProtocolVersion > 1 )
   {
      this.jServerRmiInterface.addAppenderFilter(loggerName, filter);
   }
}
 
Example 38
Project: MFIBlocking   File: TestAppender.java   Source Code and License 5 votes vote down vote up
public List<LoggingEvent> getLogsByLevel(Filter filter) {
    TestAppender testAppender = new TestAppender();
    testAppender.addFilter(filter);
    for (LoggingEvent event : log) {
        testAppender.doAppend(event);
    }
    return testAppender.getLog();
}
 
Example 39
Project: jcabi-log   File: VerboseProcessTest.java   Source Code and License 5 votes vote down vote up
@Override
public int decide(final LoggingEvent event) {
    final String thread = event.getThreadName();
    final int decision;
    if (thread.startsWith(VrbPrcMonitorFilter.THREADNAME_START
        + this.hash
    )) {
        decision = Filter.ACCEPT;
    } else {
        decision = Filter.DENY;
    }
    return decision;
}
 
Example 40
Project: pentaho-kettle   File: Log4jAppenderTest.java   Source Code and License 5 votes vote down vote up
@Test
public void addFilter() {
  Appender appender = getAppender();
  Filter filter = mock( Filter.class );
  appender.addFilter( filter );
  assertThat( appender.getFilter(), is( filter ) );
}
 
Example 41
Project: pentaho-kettle   File: Log4jAppenderTest.java   Source Code and License 5 votes vote down vote up
@Test
public void clearFilters() {
  Appender appender = getAppender();
  appender.addFilter( mock( Filter.class ) );
  appender.clearFilters();
  assertNull( appender.getFilter() );
}
 
Example 42
Project: logging-log4j2   File: AppenderSkeleton.java   Source Code and License 5 votes vote down vote up
@Override
public void addFilter(Filter newFilter) {
    if(headFilter == null) {
        headFilter = tailFilter = newFilter;
    } else {
        tailFilter.setNext(newFilter);
        tailFilter = newFilter;
    }
}
 
Example 43
Project: sstore-soft   File: StringAppender.java   Source Code and License 4 votes vote down vote up
@Override
public void addFilter(Filter arg0) {
    // TODO Auto-generated method stub
}
 
Example 44
Project: sstore-soft   File: StringAppender.java   Source Code and License 4 votes vote down vote up
@Override
public Filter getFilter() {
    // TODO Auto-generated method stub
    return null;
}
 
Example 45
Project: s-store   File: StringAppender.java   Source Code and License 4 votes vote down vote up
@Override
public void addFilter(Filter arg0) {
    // TODO Auto-generated method stub
}
 
Example 46
Project: s-store   File: StringAppender.java   Source Code and License 4 votes vote down vote up
@Override
public Filter getFilter() {
    // TODO Auto-generated method stub
    return null;
}
 
Example 47
Project: FSTestTools   File: SingleMessageAppender.java   Source Code and License 4 votes vote down vote up
@Override
public void addFilter(Filter filter) {
    this.filter = filter;
}
 
Example 48
Project: FSTestTools   File: SingleMessageAppender.java   Source Code and License 4 votes vote down vote up
@Override
public Filter getFilter() {
    return filter;
}
 
Example 49
Project: FSTestTools   File: AppenderForAsserts.java   Source Code and License 4 votes vote down vote up
@Override
public Filter getFilter() {
    return null;
}
 
Example 50
Project: reladomo   File: Log4JRecordingAppender.java   Source Code and License 4 votes vote down vote up
public void addFilter(Filter filter)
{
}
 
Example 51
Project: reladomo   File: Log4JRecordingAppender.java   Source Code and License 4 votes vote down vote up
public Filter getFilter()
{
    return null;
}
 
Example 52
Project: FSDevTools   File: CliContextImplTest.java   Source Code and License 4 votes vote down vote up
@Override
public Filter getFilter() {
    return null;
}
 
Example 53
Project: vso-intellij   File: TestAppender.java   Source Code and License 4 votes vote down vote up
@Override
public Filter getFilter() {
    return null;
}
 
Example 54
Project: fauxjsp   File: TestLog4jLogging.java   Source Code and License 4 votes vote down vote up
@Test
public void testLogging() {
	Log4jFactory factory = new Log4jFactory();
	org.apache.log4j.Logger loggerImpl= org.apache.log4j.Logger.getLogger("testlogger");
	
	final StringBuffer sb = new StringBuffer();
	loggerImpl.addAppender(new Appender() {
		
		@Override
		public void setName(String name) {
		}
		
		@Override
		public void setLayout(Layout layout) {
		}
		
		@Override
		public void setErrorHandler(ErrorHandler errorHandler) {
		}
		
		@Override
		public boolean requiresLayout() {
			return false;
		}
		
		@Override
		public String getName() {
			return null;
		}
		
		@Override
		public Layout getLayout() {
			return null;
		}
		
		@Override
		public Filter getFilter() {
			return null;
		}
		
		@Override
		public ErrorHandler getErrorHandler() {
			return null;
		}
		
		@Override
		public void doAppend(LoggingEvent event) {
			sb.append(event.getLevel()+" "+event.getMessage()+"\n");
		}
		
		@Override
		public void close() {
		}
		
		@Override
		public void clearFilters() {
		}
		
		@Override
		public void addFilter(Filter newFilter) {
		}
	});
	Logger logger = factory.getLogger("testlogger");
	logger.trace("trace message");
	logger.debug("debug message");
	logger.info("info message");
	logger.warn("warn message");
	logger.error("error message");
	logger.error("error exception", new RuntimeException("Testing error logger, please ignore this exception"));

	String expected = "INFO info message\n" + "WARN warn message\n" + "ERROR error message\n"
			+ "ERROR error exception\n";
	Assert.assertEquals(expected, sb.toString());
}
 
Example 55
Project: Lucee4   File: TaskAppender.java   Source Code and License 4 votes vote down vote up
@Override
public void addFilter(Filter arg0) {
	appender.addFilter(arg0);
}
 
Example 56
Project: Lucee4   File: TaskAppender.java   Source Code and License 4 votes vote down vote up
@Override
public Filter getFilter() {
	return appender.getFilter();
}
 
Example 57
Project: sakai   File: Log4jConfigurationManager.java   Source Code and License 4 votes vote down vote up
public void addFilter(Filter arg0)
{
	m_other.addFilter(arg0);
}
 
Example 58
Project: sakai   File: Log4jConfigurationManager.java   Source Code and License 4 votes vote down vote up
public Filter getFilter()
{
	return m_other.getFilter();
}
 
Example 59
Project: activemq-artemis   File: DefaultTestAppender.java   Source Code and License 4 votes vote down vote up
@Override
public Filter getFilter() {
   return null;
}
 
Example 60
Project: hibernate-l2-memcached   File: MockAppender.java   Source Code and License 4 votes vote down vote up
public void addFilter(Filter newFilter) {
    throw new UnsupportedOperationException();
}