Search in sources :

Example 1 with StatusChecker

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);
}
Also used : Status(ch.qos.logback.core.status.Status) ArrayList(java.util.ArrayList) CConfiguration(co.cask.cdap.common.conf.CConfiguration) StatusChecker(ch.qos.logback.core.status.StatusChecker) JoranException(ch.qos.logback.core.joran.spi.JoranException) LogPipelineConfigurator(co.cask.cdap.logging.pipeline.LogPipelineConfigurator)

Aggregations

JoranException (ch.qos.logback.core.joran.spi.JoranException)1 Status (ch.qos.logback.core.status.Status)1 StatusChecker (ch.qos.logback.core.status.StatusChecker)1 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1 LogPipelineConfigurator (co.cask.cdap.logging.pipeline.LogPipelineConfigurator)1 ArrayList (java.util.ArrayList)1