@Override protected void after() { TestLogbackAppender.events.clear(); setLevel(Level.INFO); try { new LogbackHelper().resetFromXml("/logback-test.xml"); } catch (JoranException e) { e.printStackTrace(); } }
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);
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(); } }
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(); } }
public void resetLogs() { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); ContextInitializer ci = new ContextInitializer(lc); lc.reset(); try { ci.autoConfig(); } catch (JoranException e) { e.printStackTrace(); } }
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(); } }
final URL url = Main.class.getClassLoader().getResource("file-logback.xml"); final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); try { final JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); configurator.doConfigure(url); final ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); root.detachAppender("STDOUT"); log.info("Set internal logback config with file [{}] and roll pattern [{}]", logFileName, rollPattern); } catch (JoranException je) { System.err.println("Failed to configure internal logback"); je.printStackTrace(System.err); }
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(); } }
// reset the default context (which may already have been initialized) // since we want to reconfigure it LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory(); lc.reset(); JoranConfigurator config = new JoranConfigurator(); config.setContext(lc); try { config.doConfigure("/path/to/config.xml"); } catch (JoranException e) { e.printStackTrace(); }
public void load() throws IOException { try { if (System.getProperty(LOGGING_DIR_PROPERTY) == null) { System.setProperty(LOGGING_DIR_PROPERTY, getLoggingDir().getAbsolutePath()); } } catch (SecurityException e) { System.out.println("Not allowed to read or write system property '" + LOGGING_DIR_PROPERTY + "'"); } LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory(); try { configurator = new LogConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(configFile); } catch (JoranException je) { System.out.println("Logback configuration error"); je.printStackTrace(); StatusPrinter.print(lc); } }
public class LogbackConfigurator { private static final Logger LOG = LoggerFactory.getLogger(LogbackConfigurator.class); public static boolean configure(String resource) throws JoranException { final InputStream configInputStream = LogbackConfigurator.class.getResourceAsStream(resource); final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); // the context was probably already configured by default configuration rules loggerContext.reset(); if(configInputStream != null) { try { configurator.doConfigure(configInputStream); } catch (JoranException e) { e.printStackTrace(); } StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext); return true; } else { LOG.error("Unable to find logback file: {}", resource); StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext); return false; } } }
public static void main(String[] args) throws InterruptedException { Logger logger = (Logger) LoggerFactory.getLogger(ConfigurationTester.class); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(args[0]); } catch (JoranException je) { je.printStackTrace(); } // Next call forces status messages to be printed on the console // StatusPrinter.print(lc); logger.debug("**Hello {}", new Bar()); MDC.put("testKey", "testValueFromMDC"); MDC.put("testKey2", "value2"); for (int i = 0; i < 64; i++) { logger.debug("logging statement {}", i); Thread.sleep(100); } Bar bar = new Bar(); bar.createLoggingRequest(); } }
public void load() throws IOException { try { if (System.getProperty(LOGGING_DIR_PROPERTY) == null) { System.setProperty(LOGGING_DIR_PROPERTY, getLoggingDir().getAbsolutePath()); } } catch (SecurityException e) { System.out.println("Not allowed to read or write system property '" + LOGGING_DIR_PROPERTY + "'"); } LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory(); try { configurator = new LogConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(configFile); } catch (JoranException je) { System.out.println("Logback configuration error"); je.printStackTrace(); StatusPrinter.print(lc); } }
public void load() throws IOException { try { if (System.getProperty(LOGGING_DIR_PROPERTY) == null) { System.setProperty(LOGGING_DIR_PROPERTY, getLoggingDir().getAbsolutePath()); } } catch (SecurityException e) { System.out.println("Not allowed to read or write system property '" + LOGGING_DIR_PROPERTY + "'"); } LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory(); try { configurator = new LogConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(configFile); } catch (JoranException je) { System.out.println("Logback configuration error"); je.printStackTrace(); StatusPrinter.print(lc); } }
private void initializeLogging() { String graviteeHome = System.getProperty("gravitee.home"); String logbackConfiguration = graviteeHome + File.separator + "config" + File.separator + "logback.xml"; File logbackConfigurationfile = new File(logbackConfiguration); // If logback configuration available, load it, else, load default logback configuration if (logbackConfigurationfile.exists()) { System.setProperty("logback.configurationFile", logbackConfigurationfile.getAbsolutePath()); StaticLoggerBinder loggerBinder = StaticLoggerBinder.getSingleton(); LoggerContext loggerContext = (LoggerContext) loggerBinder.getLoggerFactory(); loggerContext.reset(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); try { configurator.doConfigure(logbackConfigurationfile); } catch( JoranException e ) { e.printStackTrace(); } // Internal status data is printed in case of warnings or errors. StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext); } }
/** * @param loggerFactory * the logger factory context * @param stream * The input stream to be configured */ private static void configureLogback(final LoggerContext context, final InputStream stream) { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); try { configurator.doConfigure(stream); } catch (JoranException e) { // not much we can do since logger may not be configured yet e.printStackTrace(System.out); } }
/** * @param loggerFactory * the logger factory context * @param stream * The input stream to be configured */ private static void configureLogback(final LoggerContext context, final InputStream stream) { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); try { configurator.doConfigure(stream); } catch (JoranException e) { // not much we can do since logger may not be configured yet e.printStackTrace(System.out); } StatusPrinter.print(context); }
public void start(BundleContext context) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); // the context was probably already configured by default configuration // rules lc.reset(); configurator.doConfigure("src/test/input/osgi/simple.xml"); } catch (JoranException je) { je.printStackTrace(); } StatusPrinter.printInCaseOfErrorsOrWarnings(lc); Logger logger = LoggerFactory.getLogger(this.getClass()); logger.info("Activator.start()"); m_context = context; }
public Fruit buildFruit() { Context context = new ContextBase(); this.fruit = null; context.putProperty("fruitKey", "orange-"+count); // for next round count++; FruitConfigurator fruitConfigurator = new FruitConfigurator(this); fruitConfigurator.setContext(context); try { fruitConfigurator.doConfigure(eventList); } catch(JoranException je) { je.printStackTrace(); } return fruit; }