if (Option.isEmpty(conversionWord)) {
inError = true;
errorMsg = "No 'conversionWord' attribute in <conversionRule>";
getLogger().warn(errorMsg);
ec.addError(new ErrorItem(errorMsg));
return;
}
if (Option.isEmpty(converterClass)) {
inError = true;
errorMsg = "No 'converterClass' attribute in <conversionRule>";
getLogger().warn(errorMsg);
ec.addError(new ErrorItem(errorMsg));
return;
}
try {
getLogger().debug(
"About to add conversion rule [{}, {}] to layout", conversionWord, converterClass);
LoggerRepository repository = (LoggerRepository) ec.getObjectStack().get(0);
//
// cast may fail with user supplied repository
Map ruleRegistry = (Map) ((LoggerRepositoryEx) repository).getObject(PatternLayout.PATTERN_RULE_REGISTRY);
if(ruleRegistry == null) {
ruleRegistry = new HashMap();
((LoggerRepositoryEx) repository).putObject(PatternLayout.PATTERN_RULE_REGISTRY, ruleRegistry);
}
// put the new rule into the rule registry
ruleRegistry.put(conversionWord, converterClass);
} catch (Exception oops) {
inError = true;
errorMsg = "Could not add conversion rule to PatternLayout.";
getLogger().error(errorMsg, oops);
ec.addError(new ErrorItem(errorMsg));
}
}