001/* 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2026, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v2.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.classic.helpers; 015 016import java.util.ArrayList; 017import java.util.List; 018 019import ch.qos.logback.classic.PatternLayout; 020import ch.qos.logback.classic.spi.ILoggingEvent; 021import ch.qos.logback.core.AppenderBase; 022 023/** 024 * An appender used for testing. 025 * 026 * @author ceki 027 * @since 1.3.0 028 */ 029public class WithLayoutListAppender extends AppenderBase<ILoggingEvent> { 030 031 public List<String> list = new ArrayList<>(); 032 033 String pattern; 034 035 PatternLayout patternLayout; 036 037 @Override 038 public void start() { 039 if (pattern == null) { 040 addError("null pattern disallowed"); 041 return; 042 } 043 patternLayout = new PatternLayout(); 044 patternLayout.setContext(context); 045 patternLayout.setPattern(pattern); 046 patternLayout.start(); 047 if (patternLayout.isStarted()) 048 super.start(); 049 } 050 051 protected void append(ILoggingEvent e) { 052 String result = patternLayout.doLayout(e); 053 list.add(result); 054 } 055 056 public String getPattern() { 057 return pattern; 058 } 059 060 public void setPattern(String pattern) { 061 this.pattern = pattern; 062 } 063 064}