Skip to content

Commit

Permalink
allow for InsertFromJNDIModelHandler to be callable from logback-tyler
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <[email protected]>
  • Loading branch information
ceki committed Oct 15, 2024
1 parent 75bee86 commit 8bcfd9a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ static public ModelHandlerBase makeInstance2(Context context, ModelInterpretatio

@Override
protected void processScanAttrib(ModelInterpretationContext mic, ConfigurationModel configurationModel) {

// override parent to do nothing
}

@Override
public void postHandle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
ConfigurationModel configurationModel = (ConfigurationModel) model;
// post handling of scan attribute works even we need to watch for included files because the main url is
// set in GenericXMLConfigurator very early in the configuration process
postProcessScanAttrib(mic, configurationModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ch.qos.logback.core.model.InsertFromJNDIModel;
import ch.qos.logback.core.model.Model;
import ch.qos.logback.core.model.util.PropertyModelHandlerHelper;
import ch.qos.logback.core.spi.ContextAwarePropertyContainer;
import ch.qos.logback.core.util.JNDIUtil;
import ch.qos.logback.core.util.OptionHelper;

Expand All @@ -28,14 +29,22 @@ protected Class<InsertFromJNDIModel> getSupportedModelClass() {

@Override
public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
int errorCount = 0;

InsertFromJNDIModel ifjm = (InsertFromJNDIModel) model;
detachedHandle(mic, ifjm);
}

String envEntryName = mic.subst(ifjm.getEnvEntryName());
String asKey = mic.subst(ifjm.getAs());
/**
*
* @param capc
* @param ifjm
* @since 1.5.11
*/
public void detachedHandle(ContextAwarePropertyContainer capc, InsertFromJNDIModel ifjm) {
int errorCount = 0;
String envEntryName = capc.subst(ifjm.getEnvEntryName());
String asKey = capc.subst(ifjm.getAs());

String scopeStr = mic.subst(ifjm.getScopeStr());
String scopeStr = capc.subst(ifjm.getScopeStr());
Scope scope = ActionUtil.stringToScope(scopeStr);

String envEntryValue;
Expand All @@ -61,7 +70,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand
addError("[" + envEntryName + "] has null or empty value");
} else {
addInfo("Setting variable [" + asKey + "] to [" + envEntryValue + "] in [" + scope + "] scope");
PropertyModelHandlerHelper.setProperty(mic, asKey, envEntryValue, scope);
PropertyModelHandlerHelper.setProperty(capc, asKey, envEntryValue, scope);
}
} catch (NamingException e) {
addError("Failed to lookup JNDI env-entry [" + envEntryName + "]");
Expand Down

0 comments on commit 8bcfd9a

Please sign in to comment.