use of ch.qos.logback.core.status.StatusChecker in project cdap by caskdata.
the class LogPipelineLoader method load.
/**
* Creates the {@link LogPipelineSpecification} representing the given log pipeline configuration URL.
*/
private <T extends LoggerContext> LogPipelineSpecification<T> load(Provider<T> contextProvider, URL configURL) throws JoranException {
// Create one AppenderContext per config file
T context = contextProvider.get();
CConfiguration pipelineCConf = CConfiguration.copy(cConf);
LogPipelineConfigurator configurator = new LogPipelineConfigurator(pipelineCConf);
configurator.setContext(context);
configurator.doConfigure(configURL);
// Check if the configuration has any error in it.
if (!new StatusChecker(context).isErrorFree(Status.ERROR)) {
List<Status> errors = new ArrayList<>();
for (Status status : context.getStatusManager().getCopyOfStatusList()) {
if (status.getEffectiveLevel() == Status.ERROR) {
errors.add(status);
}
}
throw new JoranException("Configuration failed " + errors);
}
// Default the pipeline name to the config file name (without extension) if it is not set
if (context.getName() == null) {
String path = configURL.getPath();
int idx = path.lastIndexOf("/");
int dotIdx = path.lastIndexOf('.');
int startIdx = idx < 0 ? 0 : idx + 1;
int endIdx = dotIdx > idx ? dotIdx : path.length();
context.setName(path.substring(startIdx, endIdx));
}
byte[] checkpointPrefix = Bytes.toBytes(context.getName());
String prefixNum = configurator.getExecutionContext().getProperty(Constants.Logging.PIPELINE_CHECKPOINT_PREFIX_NUM);
if (prefixNum != null) {
try {
checkpointPrefix = Bytes.toBytes(Integer.parseInt(prefixNum));
} catch (NumberFormatException e) {
LOG.warn("Ignoring invalid {} setting for pipeline in {}", Constants.Logging.PIPELINE_CHECKPOINT_PREFIX_NUM, configURL);
}
}
return new LogPipelineSpecification<>(configURL, context, setupPipelineCConf(configurator, pipelineCConf), checkpointPrefix);
}
Aggregations