View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 2000-2008, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  
11  package ch.qos.logback.classic.joran.action;
12  
13  import org.xml.sax.Attributes;
14  
15  import ch.qos.logback.core.joran.action.Action;
16  import ch.qos.logback.core.joran.spi.InterpretationContext;
17  
18  public class ContextNameAction extends Action {
19  
20    public void begin(InterpretationContext ec, String name, Attributes attributes) {
21    }
22  
23    public void body(InterpretationContext ec, String body) {
24  
25      String finalBody = ec.subst(body);
26      addInfo("Setting logger context name as [" + finalBody + "]");
27      try {
28        context.setName(finalBody);
29      } catch (IllegalStateException e) {
30        addError("Failed to rename context [" + context.getName() + "] as ["
31            + finalBody + "]", e);
32      }
33    }
34  
35    public void end(InterpretationContext ec, String name) {
36    }
37  }