@Override public void beforeInitialize() { LoggerContext loggerContext = getLoggerContext(); if (isAlreadyInitialized(loggerContext)) { return; } super.beforeInitialize(); loggerContext.getTurboFilterList().add(FILTER); }
@Override public void initialize(LoggingInitializationContext initializationContext, String configLocation, LogFile logFile) { LoggerContext loggerContext = getLoggerContext(); if (isAlreadyInitialized(loggerContext)) { return; } super.initialize(initializationContext, configLocation, logFile); loggerContext.getTurboFilterList().remove(FILTER); markAsInitialized(loggerContext); if (StringUtils.hasText(System.getProperty(CONFIGURATION_FILE_PROPERTY))) { getLogger(LogbackLoggingSystem.class.getName()).warn( "Ignoring '" + CONFIGURATION_FILE_PROPERTY + "' system property. " + "Please use 'logging.config' instead."); } }
@Override public void cleanUp() { LoggerContext context = getLoggerContext(); markAsUninitialized(context); super.cleanUp(); context.getStatusManager().clear(); context.getTurboFilterList().remove(FILTER); }
/** * Sets up the recent events turbo filter. */ @Override public void init() { LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory(); // Ensure that it's not already there TurboFilterList list = context.getTurboFilterList(); list.addIfAbsent(RecentEventsFilter.singleton()); }
/**LogbackLoggerSpaceFactor * @param loggerContext * @param properties * @param confFile * @param source */ public LogbackLoggerSpaceFactory(SpaceId spaceId, LoggerContext loggerContext, Properties properties, URL confFile, String source) { super(source); this.spaceId = spaceId; this.loggerContext = loggerContext; this.properties = properties; this.confFile = confFile; boolean willReinitialize = false; Iterator<ReInitializeChecker> checkers = ServiceLoader.load(ReInitializeChecker.class, this.getClass().getClassLoader()).iterator(); while (checkers.hasNext()) { willReinitialize = !checkers.next().isReInitialize(); } Iterator<LogbackFilterGenerator> matchers = ServiceLoader.load( LogbackFilterGenerator.class, this.getClass().getClassLoader()).iterator(); while (matchers.hasNext() && willReinitialize) { LogbackFilterGenerator matcher = matchers.next(); this.loggerContext.getTurboFilterList().addAll( Arrays.asList(matcher.generatorFilters())); } initialize(willReinitialize); }
private TurboFilter getFirstTurboFilter() { TurboFilterList turboFilterList = loggerContext.getTurboFilterList(); return turboFilterList.get(0); }
@Test public void testLoggingContextReset() { addYesFilter(); assertNotNull(context.getTurboFilterList().get(0)); context.reset(); assertEquals(0, context.getTurboFilterList().size()); }
@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. 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; } } }
public static void install() { if (installed) return; System.setSecurityManager(new ThreadAwareSecurityManager()); // 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 // executiing 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 configration, // while executing sandboxed UDF code. 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; }
@Test public void testTurboFilterWithStringList() throws JoranException { // Although this test uses turbo filters, it only checks // that Joran can see <user> elements, and behave correctly // that is call the addUser method and pass the correct values // to that method. configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "turbo2.xml"); // StatusPrinter.print(loggerContext.getStatusManager()); TurboFilter filter = loggerContext.getTurboFilterList().get(0); assertTrue(filter instanceof DebugUsersTurboFilter); DebugUsersTurboFilter dutf = (DebugUsersTurboFilter) filter; assertEquals(2, dutf.getUsers().size()); }
@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. 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; } } }
@Test public void turboFilter() throws JoranException { // Although this test uses turbo filters, it only checks // that Joran can see the xml element and create // and place the relevant object correctly. configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "turbo.xml"); TurboFilter filter = loggerContext.getTurboFilterList().get(0); assertTrue(filter instanceof NOPTurboFilter); }
loggerContext.getTurboFilterList().remove(DefaultLogbackFilterGenerator.FILTER); markAsReInitialized(loggerContext); initProperties(loggerContext, properties);