public void addTo(String to) { if (to == null || to.length() == 0) { throw new IllegalArgumentException("Null or empty <to> property"); } PatternLayoutBase plb = makeNewToPatternLayout(to.trim()); plb.setContext(context); plb.start(); this.toPatternLayoutList.add(plb); }
private List<InternetAddress> parseAddress(E event) { int len = toPatternLayoutList.size(); List<InternetAddress> iaList = new ArrayList<InternetAddress>(); for (int i = 0; i < len; i++) { try { PatternLayoutBase<E> emailPL = toPatternLayoutList.get(i); String emailAdrr = emailPL.doLayout(event); if (emailAdrr == null || emailAdrr.length() == 0) { continue; } InternetAddress[] tmp = InternetAddress.parse(emailAdrr, true); iaList.addAll(Arrays.asList(tmp)); } catch (AddressException e) { addError("Could not parse email address for [" + toPatternLayoutList.get(i) + "] for event [" + event + "]", e); return iaList; } } return iaList; }
public void start() { if(pattern == null || pattern.length() == 0) { addError("Empty or null pattern."); return; } try { Parser<E> p = new Parser<E>(pattern); if (getContext() != null) { p.setContext(getContext()); } Node t = p.parse(); this.head = p.compile(t, getEffectiveConverterMap()); if (postCompileProcessor != null) { postCompileProcessor.process(head); } ConverterUtil.setContextForConverters(getContext(), head); ConverterUtil.startConverters(this.head); super.start(); } catch (ScanException sce) { StatusManager sm = getContext().getStatusManager(); sm.add(new ErrorStatus("Failed to parse pattern \"" + getPattern() + "\".", this, sce)); } }
/** * Returns a map where the default converter map is merged with the map * contained in the context. */ public Map<String, String> getEffectiveConverterMap() { Map<String, String> effectiveMap = new HashMap<String, String>(); // add the least specific map fist Map<String, String> defaultMap = getDefaultConverterMap(); if (defaultMap != null) { effectiveMap.putAll(defaultMap); } // contextMap is more specific than the default map Context context = getContext(); if (context != null) { @SuppressWarnings("unchecked") Map<String, String> contextMap = (Map<String, String>) context .getObject(CoreConstants.PATTERN_RULE_REGISTRY); if (contextMap != null) { effectiveMap.putAll(contextMap); } } // set the most specific map last effectiveMap.putAll(instanceConverterMap); return effectiveMap; }
@Test public void testPercentAsLiteral() { PatternLayoutBase<Object> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); plb.setPattern("hello \\% world"); plb.start(); String s = plb.doLayout(new Object()); assertEquals("hello % world", s); }
protected PatternLayoutBase<Event> buildLayout(String format) { PatternLayoutBase<Event> layout = createLayout(); layout.setContext(contextAware.getContext()); layout.setPattern(format); layout.setPostCompileProcessor(null); // Remove EnsureLineSeparation which is there by default layout.start(); return layout; }
public void start() { try { Parser<E> p = new Parser<E>(pattern); if (getContext() != null) { p.setContext(getContext()); } Node t = p.parse(); this.head = p.compile(t, getEffectiveConverterMap()); if (postCompileProcessor != null) { postCompileProcessor.process(head); } setContextForConverters(head); ConverterUtil.startConverters(this.head); super.start(); } catch (ScanException sce) { StatusManager sm = getContext().getStatusManager(); sm.add(new ErrorStatus("Failed to parse pattern \"" + getPattern() + "\".", this, sce)); } }
public List<String> getToAsListOfString() { List<String> toList = new ArrayList<String>(); for (PatternLayoutBase plb : toPatternLayoutList) { toList.add(plb.getPattern()); } return toList; }
@Test public void testStarted() { PatternLayoutBase<E> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); String s = plb.doLayout(getEventObject()); assertEquals("", s); StatusManager sm = context.getStatusManager(); StatusPrinter.print(sm); }
/** * * @param head * @deprecated Use {@link ConverterUtil#setContextForConverters} instead. This method will * be removed in future releases. */ protected void setContextForConverters(Converter<E> head) { ConverterUtil.setContextForConverters(getContext(), head); }
@Override public String getPresentationHeader() { if(outputPatternAsHeader) return getPresentationHeaderPrefix()+pattern; else return super.getPresentationHeader(); } }
private void startWrapped(Layout<Event> wrapped) { if (wrapped instanceof PatternLayoutBase) { /* * Don't ensure exception output (for ILoggingEvents) * or line separation (for IAccessEvents) */ PatternLayoutBase<Event> layout = (PatternLayoutBase<Event>) wrapped; layout.setPostCompileProcessor(null); /* * The pattern will be re-parsed during start. * Needed so that the pattern is re-parsed without * the postCompileProcessor. */ layout.start(); } if (wrapped != null && !wrapped.isStarted()) { wrapped.start(); } }
@Override public void start() { if (getPattern().equalsIgnoreCase(CLF_PATTERN_NAME) || getPattern().equalsIgnoreCase(CLF_PATTERN_NAME_2)) { setPattern(CLF_PATTERN); } else if (getPattern().equalsIgnoreCase(COMBINED_PATTERN_NAME)) { setPattern(COMBINED_PATTERN); } super.start(); }
@Test public void testEscapeClosingParentheses() { PatternLayoutBase<Object> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); plb.setPattern("x(%OTT\\)y"); plb.start(); String s = plb.doLayout(new Object()); assertEquals("x(123)y", s); }
/** * Returns a map where the default converter map is merged with the map * contained in the context. */ public Map<String, String> getEffectiveConverterMap() { Map<String, String> effectiveMap = new HashMap<String, String>(); // add the least specific map fist Map<String, String> defaultMap = getDefaultConverterMap(); if (defaultMap != null) { effectiveMap.putAll(defaultMap); } // contextMap is more specific than the default map Context context = getContext(); if (context != null) { @SuppressWarnings("unchecked") Map<String, String> contextMap = (Map<String, String>) context.getObject(CoreConstants.PATTERN_RULE_REGISTRY); if (contextMap != null) { effectiveMap.putAll(contextMap); } } // set the most specific map last effectiveMap.putAll(instanceConverterMap); return effectiveMap; }
public AbstractPropertyAndEncoder(Property property, Context context) { this.property = property; this.layout = getLayout(); this.layout.setContext(context); this.layout.setPattern(property.getValue()); this.layout.setPostCompileProcessor(null); this.layout.start(); }
public String toString() { return this.getClass().getName() + "(\"" + getPattern() + "\")"; }
@Test public void testUnStarted() { PatternLayoutBase<E> plb = getPatternLayoutBase(); Context context = new ContextBase(); plb.setContext(context); String s = plb.doLayout(getEventObject()); assertEquals("", s); StatusManager sm = context.getStatusManager(); StatusPrinter.print(sm); }
/** * * @param head the head node of the converter chain * @deprecated Use {@link ConverterUtil#setContextForConverters} instead. This method will * be removed in future releases. */ protected void setContextForConverters(Converter<E> head) { ConverterUtil.setContextForConverters(getContext(), head); }
@Override public String getPresentationHeader() { if(outputPatternAsHeader) return getPresentationHeaderPrefix()+pattern; else return super.getPresentationHeader(); } }