Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
package ch.qos.logback.classic.boolex;
import  groovy.lang.*;
import  org.codehaus.groovy.control.CompilationFailedException;

Author(s):
Ceki Gülcü
  Script script;
  public String getExpression() {
    return ;
  }
  public void setExpression(String expression) {
    this. = expression;
  }
  public void start() {
    int errors = 0;
    if ( == null || .length() == 0) {
      addError("Empty expression");
      return;
    } else {
      addInfo("Expression to evaluate [" +  + "]");
    }
    ClassLoader classLoader = getClass().getClassLoader();
    String currentPackageName = this.getClass().getPackage().getName();
    currentPackageName = currentPackageName.replace('.''/');
    String scriptText = FileUtil.resourceAsString(thisclassLoadercurrentPackageName + "/EvaluatorTemplate.groovy");
    if (scriptText == null) {
      return;
    }
    // insert the expression into script text
    scriptText = scriptText.replace("//EXPRESSION");
    GroovyClassLoader gLoader = new GroovyClassLoader(classLoader);
    try {
      Class scriptClass = gLoader.parseClass(scriptText);
      GroovyObject goo = (GroovyObject) scriptClass.newInstance();
       = (IEvaluatorgoo;
    } catch (CompilationFailedException cfe) {
      addError("Failed to compile expression [" +  + "]"cfe);
      errors++;
    } catch (Exception e) {
      addError("Failed to compile expression [" +  + "]"e);
      errors++;
    }
    if (errors == 0)
      super.start();
  }
  public boolean evaluate(ILoggingEvent eventthrows NullPointerExceptionEvaluationException {
    if ( == null) {
      return false;
    }
    return .doEvaluate(event);
  }
New to GrepCode? Check out our FAQ X