Refine search
void joranConfigureByResource(URL url) throws JoranException { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(url); }
static public void configureLC(LoggerContext lc, String configFile) throws JoranException { JoranConfigurator configurator = new JoranConfigurator(); lc.reset(); configurator.setContext(lc); configurator.doConfigure(configFile); } }
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"); }
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); }
/** * 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)); }
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();
/** * Configure SLF4J. * * @param is input stream to logback configuration xml */ public static void configure(InputStream is) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { String[] names = { "ch.qos.logback.classic.LoggerContext", "ch.qos.logback.classic.joran.JoranConfigurator", }; for (String name : names) { Class.forName(name, false, cl); } ch.qos.logback.classic.LoggerContext context = (ch.qos.logback.classic.LoggerContext) LoggerFactory.getILoggerFactory(); ch.qos.logback.classic.joran.JoranConfigurator configurator = new ch.qos.logback.classic.joran.JoranConfigurator(); configurator.setContext(context); context.reset(); configurator.doConfigure(is); } catch (ClassNotFoundException e) { System.err.println("WLogC: Logback JARs are missing in classpath"); } catch (NoClassDefFoundError e) { System.err.println("WLogC: Logback JARs are missing in classpath"); } catch (Throwable e) { e.printStackTrace(); } }
/** * 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); }
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); }
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); } }
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"); } }
private void initLogback(final CoreConfigure cfg) { final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); final JoranConfigurator configurator = new JoranConfigurator(); final File configureFile = new File(cfg.getCfgLibPath() + File.separator + "sandbox-logback.xml"); configurator.setContext(loggerContext); loggerContext.reset(); InputStream is = null; try { is = new FileInputStream(configureFile); initNamespaceConvert(cfg.getNamespace()); configurator.doConfigure(is); logger.info(SandboxStringUtils.getLogo()); logger.info("initializing logback success. file={};", configureFile); } catch (Throwable cause) { logger.warn("initialize logback failed. file={};", configureFile, cause); } finally { IOUtils.closeQuietly(is); } }
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 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); } }
configurator.setContext(context); context.reset(); configurator.doConfigure(logbackConfigurationFileAsURL);
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."); } } }
configurator.setContext(lc); lc.reset(); configurator.doConfigure(namesrvConfig.getRocketmqHome() + "/conf/logback_namesrv.xml");
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); } } }
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()); } } }
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(brokerConfig.getRocketmqHome() + "/conf/logback_broker.xml");