Search in sources :

Example 1 with Context

use of ch.qos.logback.core.Context in project cdap by caskdata.

the class LogPipelineLoader method setupPipelineCConf.

/**
   * Copies overridable configurations from the pipeline configuration into the given {@link CConfiguration}.
   */
private CConfiguration setupPipelineCConf(JoranConfigurator configurator, CConfiguration cConf) {
    Context context = configurator.getContext();
    // The list of properties that can be overridden per pipeline configuration
    Set<String> keys = ImmutableSet.of(Constants.Logging.PIPELINE_BUFFER_SIZE, Constants.Logging.PIPELINE_EVENT_DELAY_MS, Constants.Logging.PIPELINE_KAFKA_FETCH_SIZE, Constants.Logging.PIPELINE_CHECKPOINT_INTERVAL_MS, Constants.Logging.PIPELINE_LOGGER_CACHE_SIZE, Constants.Logging.PIPELINE_LOGGER_CACHE_EXPIRATION_MS);
    // defined in the logback xml.
    for (String key : keys) {
        context.putProperty(key, cConf.get(key));
        cConf.set(key, configurator.getExecutionContext().subst("${" + key + "}"));
    }
    return cConf;
}
Also used : Context(ch.qos.logback.core.Context) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 2 with Context

use of ch.qos.logback.core.Context in project OpenClinica by OpenClinica.

the class LoggerStartupListener method start.

@Override
public void start() {
    if (started)
        return;
    Context context = getContext();
    if (resourceLoader == null)
        resourceLoader = new DefaultResourceLoader();
    try {
        webapp = getWebAppName(resourceLoader.getResource("/").getURI().getPath());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        DATAINFO = loadProperties("datainfo.properties");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    getPropertiesSource();
    context.putProperty("log.dir", getField("log.dir"));
    context.putProperty("logLocation", getField("logLocation"));
    context.putProperty("logLevel", getField("logLevel"));
    context.putProperty("hibernateSQLLogLevel", getField("hibernateSQLLogLevel"));
    context.putProperty("hibernateTypeLogLevel", getField("hibernateTypeLogLevel"));
    started = true;
}
Also used : Context(ch.qos.logback.core.Context) LoggerContext(ch.qos.logback.classic.LoggerContext) IOException(java.io.IOException) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader)

Example 3 with Context

use of ch.qos.logback.core.Context in project cdap by caskdata.

the class ProgramRunners method createLogbackJar.

/**
   * Creates a jar that contains a logback.xml configured for the current process
   *
   * @param targetLocation the jar location
   * @return the {@link Location} where the jar was created to or {@code null} if "logback.xml" is not found
   *         in the current ClassLoader.
   * @throws IOException if failed in reading the logback xml or writing out the jar
   */
@Nullable
public static Location createLogbackJar(Location targetLocation) throws IOException {
    ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
    if (!(loggerFactory instanceof Context)) {
        return null;
    }
    URL logbackURL = ConfigurationWatchListUtil.getMainWatchURL((Context) loggerFactory);
    if (logbackURL == null) {
        return null;
    }
    try (InputStream input = logbackURL.openStream()) {
        try (JarOutputStream output = new JarOutputStream(targetLocation.getOutputStream())) {
            output.putNextEntry(new JarEntry("logback.xml"));
            ByteStreams.copy(input, output);
        }
        return targetLocation;
    }
}
Also used : Context(ch.qos.logback.core.Context) ILoggerFactory(org.slf4j.ILoggerFactory) InputStream(java.io.InputStream) JarOutputStream(java.util.jar.JarOutputStream) JarEntry(java.util.jar.JarEntry) URL(java.net.URL) Nullable(javax.annotation.Nullable)

Aggregations

Context (ch.qos.logback.core.Context)3 LoggerContext (ch.qos.logback.classic.LoggerContext)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 JarEntry (java.util.jar.JarEntry)1 JarOutputStream (java.util.jar.JarOutputStream)1 Nullable (javax.annotation.Nullable)1 ILoggerFactory (org.slf4j.ILoggerFactory)1 DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)1