[logback-user] Joran and variable substitution
Ralph Goers
rgoers at apache.org
Sat Jan 1 09:36:17 CET 2011
If all you are looking for is variable replacement then you could look at commons-lang's StrSubstitutor class. Commons Configuration's ConfigurationInterpolator provides an example of how it can be used to resolve variables from multiple StrLookup sources, including SLF4J's MDCLookup.
Ralph
On Dec 30, 2010, at 1:18 PM, Oliver Geishuettner wrote:
>
> 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
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user
More information about the Logback-user
mailing list