/** * Once the children elements are also parsed, now is the time to activate the * evaluator options. */ @SuppressWarnings("unchecked") public void end(InterpretationContext ec, String e) { if (inError) { return; } if (evaluator instanceof LifeCycle) { ((LifeCycle) evaluator).start(); addInfo("Starting evaluator named [" + evaluator.getName() + "]"); } Object o = ec.peekObject(); if (o != evaluator) { addWarn("The object on the top the of the stack is not the evaluator pushed earlier."); } else { ec.popObject(); try { Map<String, EventEvaluator<?>> evaluatorMap = (Map<String, EventEvaluator<?>>) context .getObject(CoreConstants.EVALUATOR_MAP); if(evaluatorMap == null) { addError("Could not find EvaluatorMap"); } else { evaluatorMap.put(evaluator.getName(), evaluator); } } catch (Exception ex) { addError("Could not set evaluator named [" + evaluator + "].", ex); } } }
/** * Instantiates an evaluator of the given class and sets its name. */ public void begin(InterpretationContext ec, String name, Attributes attributes) { // Let us forget about previous errors (in this instance) inError = false; evaluator = null; String className = attributes.getValue(CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(className)) { className = defaultClassName(); addInfo("Assuming default evaluator class [" + className + "]"); } if (OptionHelper.isEmpty(className)) { className = defaultClassName(); inError = true; addError("Mandatory \"" + CLASS_ATTRIBUTE + "\" attribute not set for <evaluator>"); return; } String evaluatorName = attributes.getValue(Action.NAME_ATTRIBUTE); if (OptionHelper.isEmpty(evaluatorName)) { inError = true; addError("Mandatory \"" + NAME_ATTRIBUTE + "\" attribute not set for <evaluator>"); return; } try { evaluator = (EventEvaluator<?>) OptionHelper.instantiateByClassName( className, ch.qos.logback.core.boolex.EventEvaluator.class, context); evaluator.setContext(this.context); evaluator.setName(evaluatorName); ec.pushObject(evaluator); addInfo("Adding evaluator named [" + evaluatorName + "] to the object stack"); } catch (Exception oops) { inError = true; addError("Could not create evaluator of type " + className + "].", oops); } }
public EventEvaluator<E> getEvaluator() { return evaluator; }
public void setEvaluator(EventEvaluator<E> evaluator) { this.evaluator = evaluator; }
@SuppressWarnings("unchecked") public void start() { String depthStr = getFirstOption(); if (depthStr == null) { return; } try { if (isRange(depthStr)) { String[] numbers = splitRange(depthStr); if (numbers.length == 2) { depthStart = Integer.parseInt(numbers[0]); depthEnd = Integer.parseInt(numbers[1]); checkRange(); } else { addError("Failed to parse depth option as range [" + depthStr + "]"); } } else { depthEnd = Integer.parseInt(depthStr); } } catch (NumberFormatException nfe) { addError("Failed to parse depth option [" + depthStr + "]", nfe); } final List optionList = getOptionList(); if (optionList != null && optionList.size() > 1) { final int optionListSize = optionList.size(); for (int i = 1; i < optionListSize; i++) { String evaluatorStr = (String) optionList.get(i); Context context = getContext(); if (context != null) { Map evaluatorMap = (Map) context .getObject(CoreConstants.EVALUATOR_MAP); EventEvaluator<ILoggingEvent> ee = (EventEvaluator<ILoggingEvent>) evaluatorMap .get(evaluatorStr); if (ee != null) { addEvaluator(ee); } } } } }
private void addEvaluator(EventEvaluator<ILoggingEvent> ee) { if (evaluatorList == null) { evaluatorList = new ArrayList<EventEvaluator<ILoggingEvent>>(); } evaluatorList.add(ee); }
public String convert(ILoggingEvent le) { StringBuilder buf = new StringBuilder(); if (evaluatorList != null) { boolean printCallerData = false; for (int i = 0; i < evaluatorList.size(); i++) { EventEvaluator<ILoggingEvent> ee = evaluatorList.get(i); try { if (ee.evaluate(le)) { printCallerData = true; break; } } catch (EvaluationException eex) { errorCount++; if (errorCount < MAX_ERROR_COUNT) { addError("Exception thrown for evaluator named [" + ee.getName() + "]", eex); } else if (errorCount == MAX_ERROR_COUNT) { ErrorStatus errorStatus = new ErrorStatus( "Exception thrown for evaluator named [" + ee.getName() + "].", this, eex); errorStatus.add(new ErrorStatus( "This was the last warning about this evaluator's errors." + "We don't want the StatusManager to get flooded.", this)); addStatus(errorStatus); } } } if (!printCallerData) { return CoreConstants.EMPTY_STRING; } } StackTraceElement[] cda = le.getCallerData(); if (cda != null && cda.length > depthStart) { int limit = depthEnd < cda.length ? depthEnd : cda.length; for (int i = depthStart; i < limit; i++) { buf.append(getCallerLinePrefix()); buf.append(i); buf.append("\t at "); buf.append(cda[i]); buf.append(CoreConstants.LINE_SEPARATOR); } return buf.toString(); } else { return CallerData.CALLER_DATA_NA; } }
@SuppressWarnings("unchecked") public void start() { String lengthStr = getFirstOption(); if (lengthStr == null) { lengthOption = Integer.MAX_VALUE; } else { lengthStr = lengthStr.toLowerCase(); if ("full".equals(lengthStr)) { lengthOption = Integer.MAX_VALUE; } else if ("short".equals(lengthStr)) { lengthOption = 1; } else { try { lengthOption = Integer.parseInt(lengthStr); } catch (NumberFormatException nfe) { addError("Could not parse [" + lengthStr + "] as an integer"); lengthOption = Integer.MAX_VALUE; } } } final List optionList = getOptionList(); if (optionList != null && optionList.size() > 1) { final int optionListSize = optionList.size(); for (int i = 1; i < optionListSize; i++) { String evaluatorOrIgnoredStackTraceLine = (String) optionList.get(i); Context context = getContext(); Map evaluatorMap = (Map) context.getObject(CoreConstants.EVALUATOR_MAP); EventEvaluator<ILoggingEvent> ee = (EventEvaluator<ILoggingEvent>) evaluatorMap .get(evaluatorOrIgnoredStackTraceLine); if (ee != null) { addEvaluator(ee); } else { addIgnoreStackTraceLine(evaluatorOrIgnoredStackTraceLine); } } } super.start(); }
public String convert(ILoggingEvent event) { IThrowableProxy tp = event.getThrowableProxy(); if (tp == null) { return CoreConstants.EMPTY_STRING; } // an evaluator match will cause stack printing to be skipped if (evaluatorList != null) { boolean printStack = true; for (int i = 0; i < evaluatorList.size(); i++) { EventEvaluator<ILoggingEvent> ee = evaluatorList.get(i); try { if (ee.evaluate(event)) { printStack = false; break; } } catch (EvaluationException eex) { errorCount++; if (errorCount < CoreConstants.MAX_ERROR_COUNT) { addError("Exception thrown for evaluator named [" + ee.getName() + "]", eex); } else if (errorCount == CoreConstants.MAX_ERROR_COUNT) { ErrorStatus errorStatus = new ErrorStatus( "Exception thrown for evaluator named [" + ee.getName() + "].", this, eex); errorStatus.add(new ErrorStatus( "This was the last warning about this evaluator's errors." + "We don't want the StatusManager to get flooded.", this)); addStatus(errorStatus); } } } if (!printStack) { return CoreConstants.EMPTY_STRING; } } return throwableProxyToString(tp); }
/** * The <b>EventEvaluator</b> option takes a string value representing the name of the class implementing the * {@link EventEvaluator} interface. A corresponding object will be instantiated and assigned as the event evaluator * for the SMTPAppender. */ public void setEvaluator(EventEvaluator<E> eventEvaluator) { this.eventEvaluator = eventEvaluator; }
/** * The <b>EventEvaluator</b> option takes a string value representing the name * of the class implementing the {@link EventEvaluator} interface. A * corresponding object will be instantiated and assigned as the event * evaluator for the SMTPAppender. */ public void setEvaluator(EventEvaluator<E> eventEvaluator) { this.eventEvaluator = eventEvaluator; }
/** * Use the parameter as the {@link * EventEvaluator} for this SMTPAppender. */ public SMTPAppender(EventEvaluator<ILoggingEvent> eventEvaluator) { this.eventEvaluator = eventEvaluator; }
/** * Use <code>evaluator</code> passed as parameter as the {@link * EventEvaluator} for this SMTPAppender. */ public SMTPAppender(EventEvaluator<IAccessEvent> evaluator) { this.eventEvaluator = evaluator; }