[logback-user] Joran and variable substitution

Oliver Geishuettner Garbage at gmx.de
Thu Dec 30 22:18:40 CET 2010

Thanks for the hint, this lead me in the right direction !
I found out that a simple context.subst in e.g. the begin part of the action is sufficient. To make things easier for me I created a small helper class: 
public final class VariableHelper {
 final static Logger log = LoggerFactory.getLogger(VariableHelper.class);
 private InterpretationContext context = null;
 private Attributes attrs = null;
 private VariableHelper( InterpretationContext context, Attributes attrs ) {
  this.context = context;
  this.attrs = attrs;  
 public static String replace(final InterpretationContext ic,
   final String str) {
  String ret = null;
  log.debug("before subst '{}'", str);
  ret = ic.subst(str);
  log.debug("after subst: '{}'", ret);
  return ret;
 public static String replace(final InterpretationContext ic,
   final Attributes attrs, final String attrName) {
  return replace(ic, attrs.getValue(attrName));
 public String replace( String attrName ) {
  return replace( context, attrs, attrName );
 public static VariableHelper createInstance( final InterpretationContext context, final Attributes attrs ) {
  return new VariableHelper( context, attrs );
This class can be used like this:
public class FooBarAction extends Action {
 public void begin(InterpretationContext context, String arg1,
   Attributes attributes) throws ActionException {
  VariableHelper vh = VariableHelper.createInstance(context, attributes);
  String foo = vh.replace("foo");
  String bar = vh.replace("sbar");
This is a replacement for:
String foo = attributes.getValue( "foo" );
foo = context.subst("foo" );
Perhaps this is of help for somebody.
-------- Original-Nachricht --------
> Datum: Thu, 30 Dec 2010 13:35:37 +0100
> Von: Ceki Gulcu <ceki at qos.ch>
> An: logback users list <logback-user at qos.ch>
> Betreff: Re: [logback-user] Joran and variable substitution

> Hi Marge,
> Variable substitution is done by Joran actions on an individual
> basis. Search for usages of the subst() method of the
> InterpretationContext class.

Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!  
Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail

More information about the Logback-user mailing list