void joranConfigureByResource(URL url) throws JoranException { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(url); }
private void fireDoneReconfiguring() { if(listeners == null) return; for(ReconfigureOnChangeTaskListener listener: listeners) listener.doneReconfiguring(); }
private void fireEnteredRunMethod() { if(listeners == null) return; for(ReconfigureOnChangeTaskListener listener: listeners) listener.enteredRunMethod(); }
private void performXMLConfiguration(LoggerContext lc, URL mainConfigurationURL) { JoranConfigurator jc = new JoranConfigurator(); jc.setContext(context); StatusUtil statusUtil = new StatusUtil(context); List<SaxEvent> eventList = jc.recallSafeConfiguration(); URL mainURL = ConfigurationWatchListUtil.getMainWatchURL(context); lc.reset(); long threshold = System.currentTimeMillis(); try { jc.doConfigure(mainConfigurationURL); if (statusUtil.hasXMLParsingErrors(threshold)) { fallbackConfiguration(lc, eventList, mainURL); } } catch (JoranException e) { fallbackConfiguration(lc, eventList, mainURL); } }
private void fallbackConfiguration(LoggerContext lc, List<SaxEvent> eventList, URL mainURL) { // failsafe events are used only in case of errors. Therefore, we must *not* // invoke file inclusion since the included files may be the cause of the error. List<SaxEvent> failsafeEvents = removeIncludeEvents(eventList); JoranConfigurator joranConfigurator = new JoranConfigurator(); joranConfigurator.setContext(context); ConfigurationWatchList oldCWL = ConfigurationWatchListUtil.getConfigurationWatchList(context); ConfigurationWatchList newCWL = oldCWL.buildClone(); if (failsafeEvents == null || failsafeEvents.isEmpty()) { addWarn("No previous configuration to fall back on."); } else { addWarn(FALLING_BACK_TO_SAFE_CONFIGURATION); try { lc.reset(); ConfigurationWatchListUtil.registerConfigurationWatchList(context, newCWL); joranConfigurator.doConfigure(failsafeEvents); addInfo(RE_REGISTERING_PREVIOUS_SAFE_CONFIGURATION); joranConfigurator.registerSafeConfiguration(eventList); addInfo("after registerSafeConfiguration: " + eventList); } catch (JoranException e) { addError("Unexpected exception thrown by a configuration considered safe.", e); } } }
private void fallbackConfiguration(LoggerContext lc, List<SaxEvent> eventList, URL mainURL) { JoranConfigurator joranConfigurator = new JoranConfigurator(); joranConfigurator.setContext(context); if (eventList != null) { addWarn("Falling back to previously registered safe configuration."); try { lc.reset(); JoranConfigurator.informContextOfURLUsedForConfiguration(context, mainURL); joranConfigurator.doConfigure(eventList); addInfo("Re-registering previous fallback configuration once more as a fallback configuration point"); joranConfigurator.registerSafeConfiguration(eventList); } catch (JoranException e) { addError("Unexpected exception thrown by a configuration considered safe.", e); } } else { addWarn("No previous configuration to fall back on."); } } }
private void configureByResourceUrl( LoggingInitializationContext initializationContext, LoggerContext loggerContext, URL url) throws JoranException { if (url.toString().endsWith("xml")) { JoranConfigurator configurator = new SpringBootJoranConfigurator( initializationContext); configurator.setContext(loggerContext); configurator.doConfigure(url); } else { new ContextInitializer(loggerContext).configureByResource(url); } }
void processScanAttrib(InterpretationContext ic, Attributes attributes) { String scanAttrib = ic.subst(attributes.getValue(SCAN_ATTR)); if (!OptionHelper.isEmpty(scanAttrib) && !"false".equalsIgnoreCase(scanAttrib)) { ScheduledExecutorService scheduledExecutorService = context.getScheduledExecutorService(); URL mainURL = ConfigurationWatchListUtil.getMainWatchURL(context); if (mainURL == null) { addWarn("Due to missing top level configuration file, reconfiguration on change (configuration file scanning) cannot be done."); return; } ReconfigureOnChangeTask rocTask = new ReconfigureOnChangeTask(); rocTask.setContext(context); context.putObject(CoreConstants.RECONFIGURE_ON_CHANGE_TASK, rocTask); String scanPeriodAttrib = ic.subst(attributes.getValue(SCAN_PERIOD_ATTR)); Duration duration = getDuration(scanAttrib, scanPeriodAttrib); if (duration == null) { return; } addInfo("Will scan for changes in [" + mainURL + "] "); // Given that included files are encountered at a later phase, the complete list of files // to scan can only be determined when the configuration is loaded in full. // However, scan can be active if mainURL is set. Otherwise, when changes are detected // the top level config file cannot be accessed. addInfo("Setting ReconfigureOnChangeTask scanning period to " + duration); ScheduledFuture<?> scheduledFuture = scheduledExecutorService.scheduleAtFixedRate(rocTask, duration.getMilliseconds(), duration.getMilliseconds(), TimeUnit.MILLISECONDS); context.addScheduledFuture(scheduledFuture); } }
private void fireChangeDetected() { if(listeners == null) return; for(ReconfigureOnChangeTaskListener listener: listeners) listener.changeDetected(); }
@Override public void addInstanceRules(RuleStore rs) { super.addInstanceRules(rs); Environment environment = this.initializationContext.getEnvironment(); rs.addRule(new ElementSelector("configuration/springProperty"), new SpringPropertyAction(environment)); rs.addRule(new ElementSelector("*/springProfile"), new SpringProfileAction(environment)); rs.addRule(new ElementSelector("*/springProfile/*"), new NOPAction()); }
static public void configureLC(LoggerContext lc, String configFile) throws JoranException { JoranConfigurator configurator = new JoranConfigurator(); lc.reset(); configurator.setContext(lc); configurator.doConfigure(configFile); } }
private void performXMLConfiguration(LoggerContext lc) { JoranConfigurator jc = new JoranConfigurator(); jc.setContext(context); StatusUtil statusUtil = new StatusUtil(context); List<SaxEvent> eventList = jc.recallSafeConfiguration(); URL mainURL = ConfigurationWatchListUtil.getMainWatchURL(context); lc.reset(); long threshold = System.currentTimeMillis(); try { jc.doConfigure(mainConfigurationURL); if (statusUtil.hasXMLParsingErrors(threshold)) { fallbackConfiguration(lc, eventList, mainURL); } } catch (JoranException e) { fallbackConfiguration(lc, eventList, mainURL); } }
private void configureLoggerContextByURL(LoggerContext context, URL url) { try { JoranConfigurator configurator = new JoranConfigurator(); context.reset(); configurator.setContext(context); configurator.doConfigure(url); } catch (JoranException e) { } StatusPrinter.printInCaseOfErrorsOrWarnings(context); }
private static void initLogback() throws JoranException { String rocketmqHome = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV)); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(rocketmqHome + "/conf/logback_tools.xml"); }
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); loggerContext.reset(); JoranConfigurator configurator = new JoranConfigurator(); InputStream configStream = FileUtils.openInputStream(logbackPropertiesUserFile); configurator.setContext(loggerContext); configurator.doConfigure(configStream); // loads logback file configStream.close();
/** * Generally used to reset logback in logging tests */ public void resetFromXml(String xmlResourcePath) throws JoranException { LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); context.reset(); configurator.doConfigure(LogbackHelper.class.getResource(xmlResourcePath)); }
protected void configureWith(URL resource) { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext((LoggerContext) loggerFactory); ((LoggerContext) loggerFactory).reset(); // the statusManager keeps a copy of all logback status messages even after reset, so we clear that ((LoggerContext) loggerFactory).getStatusManager().clear(); try { configurator.doConfigure(resource); } catch (JoranException ignore) { } StatusPrinter.printInCaseOfErrorsOrWarnings((Context) loggerFactory); }
/** * Note that this method closes the input stream */ private static void configure(InputStream input, Map<String, String> substitutionVariables) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(configureContext(lc, substitutionVariables)); configurator.doConfigure(input); } catch (JoranException e) { // StatusPrinter will handle this } finally { IOUtils.closeQuietly(input); } StatusPrinter.printInCaseOfErrorsOrWarnings(lc); }
public void configureByResource(URL url) throws JoranException { if (url == null) { throw new IllegalArgumentException("URL argument cannot be null"); } final String urlString = url.toString(); if (urlString.endsWith("groovy")) { if (EnvUtil.isGroovyAvailable()) { // avoid directly referring to GafferConfigurator so as to avoid // loading groovy.lang.GroovyObject . See also http://jira.qos.ch/browse/LBCLASSIC-214 GafferUtil.runGafferConfiguratorOn(loggerContext, this, url); } else { StatusManager sm = loggerContext.getStatusManager(); sm.add(new ErrorStatus("Groovy classes are not available on the class path. ABORTING INITIALIZATION.", loggerContext)); } } else if (urlString.endsWith("xml")) { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(url); } else { throw new LogbackException("Unexpected filename extension of file [" + url.toString() + "]. Should be either .groovy or .xml"); } }
public void reloadByURL(URL url) throws JoranException { StatusListenerAsList statusListenerAsList = new StatusListenerAsList(); addStatusListener(statusListenerAsList); addInfo("Resetting context: " + loggerContext.getName()); loggerContext.reset(); // after a reset the statusListenerAsList gets removed as a listener addStatusListener(statusListenerAsList); try { if (url != null) { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(url); addInfo("Context: " + loggerContext.getName() + " reloaded."); } } finally { removeStatusListener(statusListenerAsList); if (debug) { StatusPrinter.print(statusListenerAsList.getStatusList()); } } }