-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more work on model based configuration
- Loading branch information
Showing
42 changed files
with
1,698 additions
and
686 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LevelActionOld.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2015, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package ch.qos.logback.classic.joran.action; | ||
|
||
import org.xml.sax.Attributes; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.core.joran.action.Action; | ||
import ch.qos.logback.core.joran.action.ActionConst; | ||
import ch.qos.logback.core.joran.spi.InterpretationContext; | ||
|
||
/** | ||
* Action to handle the <level> element nested within <logger> element. | ||
* | ||
* <p>This action is <b>deprecated</b>. Use the level attribute within the logger | ||
* element. | ||
* | ||
* @author Ceki Gulcu | ||
*/ | ||
public class LevelActionOld extends Action { | ||
|
||
boolean inError = false; | ||
|
||
public void begin(InterpretationContext ec, String name, Attributes attributes) { | ||
Object o = ec.peekObject(); | ||
|
||
if (!(o instanceof Logger)) { | ||
inError = true; | ||
addError("For element <level>, could not find a logger at the top of execution stack."); | ||
return; | ||
} | ||
|
||
Logger l = (Logger) o; | ||
|
||
String loggerName = l.getName(); | ||
|
||
String levelStr = ec.subst(attributes.getValue(ActionConst.VALUE_ATTR)); | ||
// addInfo("Encapsulating logger name is [" + loggerName | ||
// + "], level value is [" + levelStr + "]."); | ||
|
||
if (ActionConst.INHERITED.equalsIgnoreCase(levelStr) || ActionConst.NULL.equalsIgnoreCase(levelStr)) { | ||
l.setLevel(null); | ||
} else { | ||
l.setLevel(Level.toLevel(levelStr, Level.DEBUG)); | ||
} | ||
|
||
addInfo(loggerName + " level set to " + l.getLevel()); | ||
} | ||
|
||
public void finish(InterpretationContext ec) { | ||
} | ||
|
||
public void end(InterpretationContext ec, String e) { | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
logback-classic/src/main/java/ch/qos/logback/classic/joran/action/LoggerActionOld.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2015, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package ch.qos.logback.classic.joran.action; | ||
|
||
import org.xml.sax.Attributes; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.LoggerContext; | ||
import ch.qos.logback.core.joran.action.Action; | ||
import ch.qos.logback.core.joran.action.ActionConst; | ||
import ch.qos.logback.core.joran.spi.InterpretationContext; | ||
import ch.qos.logback.core.util.OptionHelper; | ||
|
||
/** | ||
* Action which handles <logger> elements in configuration files. | ||
* | ||
* @author Ceki Gulcu | ||
*/ | ||
public class LoggerActionOld extends Action { | ||
public static final String LEVEL_ATTRIBUTE = "level"; | ||
|
||
boolean inError = false; | ||
Logger logger; | ||
|
||
public void begin(InterpretationContext ec, String name, Attributes attributes) { | ||
// Let us forget about previous errors (in this object) | ||
inError = false; | ||
logger = null; | ||
|
||
LoggerContext loggerContext = (LoggerContext) this.context; | ||
|
||
String loggerName = ec.subst(attributes.getValue(NAME_ATTRIBUTE)); | ||
|
||
if (OptionHelper.isEmpty(loggerName)) { | ||
inError = true; | ||
String aroundLine = getLineColStr(ec); | ||
String errorMsg = "No 'name' attribute in element " + name + ", around " + aroundLine; | ||
addError(errorMsg); | ||
return; | ||
} | ||
|
||
logger = loggerContext.getLogger(loggerName); | ||
|
||
String levelStr = ec.subst(attributes.getValue(LEVEL_ATTRIBUTE)); | ||
|
||
if (!OptionHelper.isEmpty(levelStr)) { | ||
if (ActionConst.INHERITED.equalsIgnoreCase(levelStr) || ActionConst.NULL.equalsIgnoreCase(levelStr)) { | ||
addInfo("Setting level of logger [" + loggerName + "] to null, i.e. INHERITED"); | ||
logger.setLevel(null); | ||
} else { | ||
Level level = Level.toLevel(levelStr); | ||
addInfo("Setting level of logger [" + loggerName + "] to " + level); | ||
logger.setLevel(level); | ||
} | ||
} | ||
|
||
String additivityStr = ec.subst(attributes.getValue(ActionConst.ADDITIVITY_ATTRIBUTE)); | ||
if (!OptionHelper.isEmpty(additivityStr)) { | ||
boolean additive = OptionHelper.toBoolean(additivityStr, true); | ||
addInfo("Setting additivity of logger [" + loggerName + "] to " + additive); | ||
logger.setAdditive(additive); | ||
} | ||
ec.pushObject(logger); | ||
} | ||
|
||
public void end(InterpretationContext ec, String e) { | ||
if (inError) { | ||
return; | ||
} | ||
Object o = ec.peekObject(); | ||
if (o != logger) { | ||
addWarn("The object on the top the of the stack is not " + logger + " pushed earlier"); | ||
addWarn("It is: " + o); | ||
} else { | ||
ec.popObject(); | ||
} | ||
} | ||
|
||
public void finish(InterpretationContext ec) { | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...sic/src/main/java/ch/qos/logback/classic/joran/action/LoggerContextListenerActionOld.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2015, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package ch.qos.logback.classic.joran.action; | ||
|
||
import ch.qos.logback.classic.spi.LoggerContextListener; | ||
import ch.qos.logback.core.spi.ContextAware; | ||
import ch.qos.logback.core.spi.LifeCycle; | ||
import org.xml.sax.Attributes; | ||
|
||
import ch.qos.logback.classic.LoggerContext; | ||
import ch.qos.logback.core.joran.action.Action; | ||
import ch.qos.logback.core.joran.spi.ActionException; | ||
import ch.qos.logback.core.joran.spi.InterpretationContext; | ||
import ch.qos.logback.core.util.OptionHelper; | ||
|
||
public class LoggerContextListenerActionOld extends Action { | ||
boolean inError = false; | ||
LoggerContextListener lcl; | ||
|
||
@Override | ||
public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { | ||
|
||
inError = false; | ||
|
||
String className = attributes.getValue(CLASS_ATTRIBUTE); | ||
if (OptionHelper.isEmpty(className)) { | ||
addError("Mandatory \"" + CLASS_ATTRIBUTE + "\" attribute not set for <contextListener> element"); | ||
inError = true; | ||
return; | ||
} | ||
|
||
try { | ||
lcl = (LoggerContextListener) OptionHelper.instantiateByClassName(className, LoggerContextListener.class, context); | ||
|
||
if (lcl instanceof ContextAware) { | ||
((ContextAware) lcl).setContext(context); | ||
} | ||
|
||
ec.pushObject(lcl); | ||
addInfo("Adding LoggerContextListener of type [" + className + "] to the object stack"); | ||
|
||
} catch (Exception oops) { | ||
inError = true; | ||
addError("Could not create LoggerContextListener of type " + className + "].", oops); | ||
} | ||
} | ||
|
||
@Override | ||
public void end(InterpretationContext ec, String name) throws ActionException { | ||
if (inError) { | ||
return; | ||
} | ||
Object o = ec.peekObject(); | ||
|
||
if (o != lcl) { | ||
addWarn("The object on the top the of the stack is not the LoggerContextListener pushed earlier."); | ||
} else { | ||
if (lcl instanceof LifeCycle) { | ||
((LifeCycle) lcl).start(); | ||
addInfo("Starting LoggerContextListener"); | ||
} | ||
((LoggerContext) context).addListener(lcl); | ||
ec.popObject(); | ||
} | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
logback-classic/src/main/java/ch/qos/logback/classic/model/LevelModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ch.qos.logback.classic.model; | ||
|
||
import ch.qos.logback.core.model.Model; | ||
|
||
public class LevelModel extends Model { | ||
|
||
String value; | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
|
||
|
||
} |
7 changes: 7 additions & 0 deletions
7
logback-classic/src/main/java/ch/qos/logback/classic/model/LoggerContextListenerModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ch.qos.logback.classic.model; | ||
|
||
import ch.qos.logback.core.model.ComponentModel; | ||
|
||
public class LoggerContextListenerModel extends ComponentModel { | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...classic/src/main/java/ch/qos/logback/classic/model/processor/ContextNameModelHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ch.qos.logback.classic.model.processor; | ||
|
||
import ch.qos.logback.classic.model.ContextNameModel; | ||
import ch.qos.logback.core.Context; | ||
import ch.qos.logback.core.joran.spi.InterpretationContext; | ||
import ch.qos.logback.core.model.Model; | ||
import ch.qos.logback.core.model.processor.ModelHandlerBase; | ||
import ch.qos.logback.core.model.processor.ModelHandlerException; | ||
|
||
public class ContextNameModelHandler extends ModelHandlerBase { | ||
|
||
public ContextNameModelHandler(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
protected Class<ContextNameModel> getSupportedModelClass() { | ||
return ContextNameModel.class; | ||
} | ||
|
||
@Override | ||
public void handle(InterpretationContext intercon, Model model) throws ModelHandlerException { | ||
ContextNameModel contextNameModel = (ContextNameModel) model; | ||
|
||
String finalBody = intercon.subst(contextNameModel.getBodyText()); | ||
addInfo("Setting logger context name as [" + finalBody + "]"); | ||
try { | ||
context.setName(finalBody); | ||
} catch (IllegalStateException e) { | ||
addError("Failed to rename context [" + context.getName() + "] as [" + finalBody + "]", e); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.