@@ -0,0 +1,2641 @@
+/*%0A * Copyright 1999,2004 The Apache Software Foundation.%0A * %0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * %0A *      http://www.apache.org/licenses/LICENSE-2.0%0A * %0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.apache.log4j.varia;%0A%0Aimport org.apache.log4j.rule.ExpressionRule;%0Aimport org.apache.log4j.rule.Rule;%0Aimport org.apache.log4j.spi.Filter;%0Aimport org.apache.log4j.spi.LoggingEvent;%0Aimport org.apache.log4j.spi.location.LocationInfo;%0A%0A%0A/**%0A * Location information is usually specified at the appender level - all events associated %0A * with an appender either create and parse stack traces or they do not.  This is%0A * an expensive operation and in some cases not needed for all events associated with%0A * an appender.%0A * %0A * This filter creates event-level location information only if the provided expression evaluates to true.%0A * %0A * For information on expression syntax, see org.apache.log4j.rule.ExpressionRule%0A * %0A * @author Scott Deboy sdeboy@apache.org%0A */%0Apublic class LocationInfoFilter extends Filter %7B%0A  boolean convertInFixToPostFix = true;%0A  String expression;%0A  Rule expressionRule;%0A%0A  public void activateOptions() %7B%0A    expressionRule =%0A      ExpressionRule.getRule(expression, !convertInFixToPostFix);%0A  %7D%0A%0A  public void setExpression(String expression) %7B%0A    this.expression = expression;%0A  %7D%0A%0A  public String getExpression() %7B%0A    return expression;%0A  %7D%0A%0A  public void setConvertInFixToPostFix(boolean convertInFixToPostFix) %7B%0A    this.convertInFixToPostFix = convertInFixToPostFix;%0A  %7D%0A%0A  public boolean getConvertInFixToPostFix() %7B%0A    return convertInFixToPostFix;%0A  %7D%0A%0A  /**%0A   * If this event does not already contain location information, %0A   * evaluate the event against the expression.%0A   * %0A   * If the expression evaluates to true, generate a LocationInfo instance %0A   * by creating an exception and set this LocationInfo on the event.%0A   * %0A   * Returns %7B@link Filter#NEUTRAL%7D%0A   */%0A  public int decide(LoggingEvent event) %7B%0A    if (!event.locationInformationExists()) %7B%0A      if (expressionRule.evaluate(event)) %7B%0A%09      Throwable t = new Exception();%0A%09      event.setLocationInformation(new LocationInfo(t, getClass().getName()));%0A      %7D%0A    %7D%0A    return Filter.NEUTRAL;%0A  %7D%0A%7D%0A

LocationInfoFilter generates LocationInfo for an event only if the provided expression evaluates to true.