@Override protected void after() { TestLogbackAppender.events.clear(); setLevel(Level.INFO); try { new LogbackHelper().resetFromXml("/logback-test.xml"); } catch (JoranException e) { e.printStackTrace(); } }
private SAXParser buildSaxParser() throws JoranException { try { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setValidating(false); spf.setNamespaceAware(true); return spf.newSAXParser(); } catch (Exception pce) { String errMsg = "Parser configuration error occurred"; addError(errMsg, pce); throw new JoranException(errMsg, pce); } }
public void execute() { File file = settings.getPath(LoggingConf.CONFIG, confPath).toFile(); System.out.println("Configuring Logback with configuration: " + file.getAbsolutePath()); LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); // Call context.reset() to clear any previous configuration, e.g. default // configuration. For multi-step configuration, omit calling context.reset(). loggerContext.reset(); try { configurator.doConfigure(file); // Not needed as this is the default behaviour from logback // StatusPrinter.print(loggerContext); } catch (JoranException e) { LOGGER.error(e.getMessage(), e); } StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext); } }
public void execute() { File file = settings.getPath(LoggingConf.CONFIG, confPath).toFile(); System.out.println("Configuring Logback with configuration: " + file.getAbsolutePath()); LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); // Call context.reset() to clear any previous configuration, e.g. default // configuration. For multi-step configuration, omit calling context.reset(). loggerContext.reset(); try { configurator.doConfigure(file); // Not needed as this is the default behaviour from logback // StatusPrinter.print(loggerContext); } catch (JoranException e) { LOGGER.error(e.getMessage(), e); } StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext); } }
public void recordEvents(InputStream inputStream) throws JoranException { try { XMLEventReader xmlEventReader = XMLInputFactory.newInstance().createXMLEventReader(inputStream); read(xmlEventReader); } catch (XMLStreamException e) { throw new JoranException("Problem parsing XML document. See previously reported errors.", e); } }
System.setProperty("log_path", my_log_path); //Reload: LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); ContextInitializer ci = new ContextInitializer(lc); lc.reset(); try { //I prefer autoConfig() over JoranConfigurator.doConfigure() so I wouldn't need to find the file myself. ci.autoConfig(); } catch (JoranException e) { // StatusPrinter will try to log this e.printStackTrace(); } StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
public static void main(String[] args) { try { LBCORE63 main = new LBCORE63(); main.start(); } catch (JoranException e) { System.out.println("Failed to load application: " + e.getMessage()); } }
private void handleError(String errMsg, Throwable t) throws JoranException { addError(errMsg, t); throw new JoranException(errMsg, t); }
private static void loggingConfigOn() { try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext((LoggerContext) LoggerFactory.getILoggerFactory()); ((LoggerContext) LoggerFactory.getILoggerFactory()).reset(); configurator.doConfigure(App.class.getResourceAsStream("/logback-cli-on.xml")); } catch (JoranException e) { e.printStackTrace(); } }
} catch (JoranException e) { LOGGER.error("Error configuring logging from file {}. '{}'", loggingFile, e.getMessage(), e);
public final void doConfigure(File file) throws JoranException { FileInputStream fis = null; try { informContextOfURLUsedForConfiguration(getContext(), file.toURI().toURL()); fis = new FileInputStream(file); doConfigure(fis); } catch (IOException ioe) { String errMsg = "Could not open [" + file.getPath() + "]."; addError(errMsg, ioe); throw new JoranException(errMsg, ioe); } finally { if (fis != null) { try { fis.close(); } catch (java.io.IOException ioe) { String errMsg = "Could not close [" + file.getName() + "]."; addError(errMsg, ioe); throw new JoranException(errMsg, ioe); } } } }
private static void loggingConfigOff() { try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext((LoggerContext) LoggerFactory.getILoggerFactory()); configurator.doConfigure(App.class.getResourceAsStream("/logback-cli-off.xml")); } catch (JoranException e) { e.printStackTrace(); } }
configURL, e.getMessage());
public List<SaxEvent> recordEvents(InputSource inputSource) throws JoranException { SAXParser saxParser = buildSaxParser(); try { saxParser.parse(inputSource, this); return saxEventList; } catch (IOException ie) { handleError("I/O error occurred while parsing xml file", ie); } catch(SAXException se) { // Exception added into StatusManager via Sax error handling. No need to add it again throw new JoranException("Problem parsing XML document. See previously reported errors.", se); } catch (Exception ex) { handleError("Unexpected exception while parsing XML document.", ex); } throw new IllegalStateException("This point can never be reached"); }
public void resetLogs() { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); ContextInitializer ci = new ContextInitializer(lc); lc.reset(); try { ci.autoConfig(); } catch (JoranException e) { e.printStackTrace(); } }
configURL, e.getMessage());
public final void doConfigure(URL url) throws JoranException { InputStream in = null; try { informContextOfURLUsedForConfiguration(getContext(), url); URLConnection urlConnection = url.openConnection(); // per http://jira.qos.ch/browse/LBCORE-105 // per http://jira.qos.ch/browse/LBCORE-127 urlConnection.setUseCaches(false); in = urlConnection.getInputStream(); doConfigure(in); } catch (IOException ioe) { String errMsg = "Could not open URL [" + url + "]."; addError(errMsg, ioe); throw new JoranException(errMsg, ioe); } finally { if (in != null) { try { in.close(); } catch (IOException ioe) { String errMsg = "Could not close input stream"; addError(errMsg, ioe); throw new JoranException(errMsg, ioe); } } } }
protected void configureLogback(final File file) { final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); final JoranConfigurator jc = new JoranConfigurator(); jc.setContext(context); context.reset(); try { jc.doConfigure(file); } catch (final JoranException e) { e.printStackTrace(); } }
System.out.println(ex.getMessage());
public void recordEvents(InputStream inputStream) throws JoranException { try { XMLEventReader xmlEventReader = XMLInputFactory.newInstance().createXMLEventReader(inputStream); read(xmlEventReader); } catch (XMLStreamException e) { throw new JoranException("Problem parsing XML document. See previously reported errors.", e); } }