Search in sources :

Example 1 with ReconfigureOnChangeFilter

use of ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter in project cassandra by apache.

the class ThreadAwareSecurityManager method install.

public static void install() {
    if (installed)
        return;
    System.setSecurityManager(new ThreadAwareSecurityManager());
    Logger l = LoggerFactory.getLogger(ThreadAwareSecurityManager.class);
    ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) l;
    LoggerContext ctx = logbackLogger.getLoggerContext();
    TurboFilterList turboFilterList = ctx.getTurboFilterList();
    for (int i = 0; i < turboFilterList.size(); i++) {
        TurboFilter turboFilter = turboFilterList.get(i);
        if (turboFilter instanceof ReconfigureOnChangeFilter) {
            ReconfigureOnChangeFilter reconfigureOnChangeFilter = (ReconfigureOnChangeFilter) turboFilter;
            turboFilterList.set(i, new SMAwareReconfigureOnChangeFilter(reconfigureOnChangeFilter));
            break;
        }
    }
    installed = true;
}
Also used : TurboFilterList(ch.qos.logback.classic.spi.TurboFilterList) Logger(org.slf4j.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) ReconfigureOnChangeFilter(ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter) TurboFilter(ch.qos.logback.classic.turbo.TurboFilter)

Example 2 with ReconfigureOnChangeFilter

use of ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter in project cassandra by apache.

the class LogbackLoggingSupport method onStartup.

@Override
public void onStartup() {
    // The default logback configuration in conf/logback.xml allows reloading the
    // configuration when the configuration file has changed (every 60 seconds by default).
    // This requires logback to use file I/O APIs. But file I/O is not allowed from UDFs.
    // I.e. if logback decides to check for a modification of the config file while
    // executing a sandbox thread, the UDF execution and therefore the whole request
    // execution will fail with an AccessControlException.
    // To work around this, a custom ReconfigureOnChangeFilter is installed, that simply
    // prevents this configuration file check and possible reload of the configuration,
    // while executing sandboxed UDF code.
    // 
    // NOTE: this is obsolte with logback versions (at least since 1.2.3)
    Logger logbackLogger = (Logger) LoggerFactory.getLogger(ThreadAwareSecurityManager.class);
    LoggerContext ctx = logbackLogger.getLoggerContext();
    TurboFilterList turboFilterList = ctx.getTurboFilterList();
    for (int i = 0; i < turboFilterList.size(); i++) {
        TurboFilter turboFilter = turboFilterList.get(i);
        if (turboFilter instanceof ReconfigureOnChangeFilter) {
            ReconfigureOnChangeFilter reconfigureOnChangeFilter = (ReconfigureOnChangeFilter) turboFilter;
            turboFilterList.set(i, new SMAwareReconfigureOnChangeFilter(reconfigureOnChangeFilter));
            break;
        }
    }
}
Also used : ThreadAwareSecurityManager(org.apache.cassandra.security.ThreadAwareSecurityManager) ReconfigureOnChangeFilter(ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter) TurboFilterList(ch.qos.logback.classic.spi.TurboFilterList) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) TurboFilter(ch.qos.logback.classic.turbo.TurboFilter)

Example 3 with ReconfigureOnChangeFilter

use of ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter in project cassandra by apache.

the class AggregationTest method configureLogbackScanPeriod.

private static void configureLogbackScanPeriod(long millis) {
    Logger l = LoggerFactory.getLogger(AggregationTest.class);
    ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) l;
    LoggerContext ctx = logbackLogger.getLoggerContext();
    TurboFilterList turboFilterList = ctx.getTurboFilterList();
    boolean done = false;
    for (TurboFilter turboFilter : turboFilterList) {
        if (turboFilter instanceof ReconfigureOnChangeFilter) {
            ReconfigureOnChangeFilter reconfigureFilter = (ReconfigureOnChangeFilter) turboFilter;
            reconfigureFilter.setContext(ctx);
            reconfigureFilter.setRefreshPeriod(millis);
            reconfigureFilter.stop();
            // start() sets the next check timestammp
            reconfigureFilter.start();
            done = true;
            break;
        }
    }
    ReconfigureOnChangeTask roct = (ReconfigureOnChangeTask) ctx.getObject(RECONFIGURE_ON_CHANGE_TASK);
    if (roct != null) {
        // Let the test run anyway, just we cannot reconfigure it (and it is pointless to reconfigure).
        return;
    }
    assertTrue("ReconfigureOnChangeFilter not in logback's turbo-filter list - do that by adding scan=\"true\" to logback-test.xml's configuration element", done);
}
Also used : ReconfigureOnChangeFilter(ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter) TurboFilterList(ch.qos.logback.classic.spi.TurboFilterList) ReconfigureOnChangeTask(ch.qos.logback.classic.joran.ReconfigureOnChangeTask) Logger(org.slf4j.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) TurboFilter(ch.qos.logback.classic.turbo.TurboFilter)

Aggregations

LoggerContext (ch.qos.logback.classic.LoggerContext)3 TurboFilterList (ch.qos.logback.classic.spi.TurboFilterList)3 ReconfigureOnChangeFilter (ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter)3 TurboFilter (ch.qos.logback.classic.turbo.TurboFilter)3 Logger (org.slf4j.Logger)2 Logger (ch.qos.logback.classic.Logger)1 ReconfigureOnChangeTask (ch.qos.logback.classic.joran.ReconfigureOnChangeTask)1 ThreadAwareSecurityManager (org.apache.cassandra.security.ThreadAwareSecurityManager)1