public static void apply(LoggingConfiguration conf) { apply(conf, "/org/sonar/batch/bootstrapper/logback.xml"); }
private static void setCustomRootAppender(LoggingConfiguration conf) { Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); String level = StringUtils.defaultIfBlank(conf.getSubstitutionVariables().get(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), LoggingConfiguration.LEVEL_ROOT_DEFAULT); if (logger.getAppender(CUSTOM_APPENDER_NAME) == null) { logger.detachAndStopAllAppenders(); logger.addAppender(createAppender(conf.getLogOutput())); } logger.setLevel(Level.toLevel(level)); }
public static void apply(LoggingConfiguration conf, File logbackFile) { Logback.configure(logbackFile, conf.getSubstitutionVariables()); if (conf.getLogOutput() != null) { setCustomRootAppender(conf); } }
private void configureLogging() { if (loggingConfig != null) { loggingConfig.setProperties(globalProperties); LoggingConfigurator.apply(loggingConfig); } }
public static void apply(LoggingConfiguration conf, String classloaderPath) { Logback.configure(classloaderPath, conf.getSubstitutionVariables()); // if not set, keep default behavior (configured to stdout through the file in classpath) if (conf.getLogOutput() != null) { setCustomRootAppender(conf); } }
private static void setCustomRootAppender(LoggingConfiguration conf) { Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); String level = StringUtils.defaultIfBlank(conf.getSubstitutionVariables().get(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), LoggingConfiguration.LEVEL_ROOT_DEFAULT); if (logger.getAppender(CUSTOM_APPENDER_NAME) == null) { logger.detachAndStopAllAppenders(); logger.addAppender(createAppender(conf.getLogOutput())); } logger.setLevel(Level.toLevel(level)); }
@Test public void testNoListener() throws UnsupportedEncodingException { System.setOut(new PrintStream(out, false, StandardCharsets.UTF_8.name())); LoggingConfigurator.apply(conf); Logger logger = LoggerFactory.getLogger(this.getClass()); logger.info("info"); assertThat(new String(out.toByteArray(), StandardCharsets.UTF_8)).contains("info"); }
public static void apply(LoggingConfiguration conf, String classloaderPath) { Logback.configure(classloaderPath, conf.getSubstitutionVariables()); // if not set, keep default behavior (configured to stdout through the file in classpath) if (conf.getLogOutput() != null) { setCustomRootAppender(conf); } }
private static void setCustomRootAppender(LoggingConfiguration conf) { Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); String level = StringUtils.defaultIfBlank(conf.getSubstitutionVariables().get(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), LoggingConfiguration.LEVEL_ROOT_DEFAULT); if (logger.getAppender(CUSTOM_APPENDER_NAME) == null) { logger.detachAndStopAllAppenders(); logger.addAppender(createAppender(conf.getLogOutput())); } logger.setLevel(Level.toLevel(level)); }
@Test public void testNoStdout() throws UnsupportedEncodingException { System.setOut(new PrintStream(out, false, StandardCharsets.UTF_8.name())); conf.setLogOutput(listener); LoggingConfigurator.apply(conf); Logger logger = LoggerFactory.getLogger(this.getClass()); logger.error(TEST_STR); logger.info(TEST_STR); logger.debug(TEST_STR); assertThat(out.size()).isEqualTo(0); }
public static void apply(LoggingConfiguration conf, String classloaderPath) { Logback.configure(classloaderPath, conf.getSubstitutionVariables()); // if not set, keep default behavior (configured to stdout through the file in classpath) if (conf.getLogOutput() != null) { setCustomRootAppender(conf); } }
@Test public void testConfigureMultipleTimes() throws UnsupportedEncodingException { System.setOut(new PrintStream(out, false, StandardCharsets.UTF_8.name())); conf.setLogOutput(listener); LoggingConfigurator.apply(conf); Logger logger = LoggerFactory.getLogger(this.getClass()); logger.debug("debug"); assertThat(listener.msg).isNull(); conf.setVerbose(true); LoggingConfigurator.apply(conf); logger.debug("debug"); assertThat(listener.msg).isEqualTo("debug"); }
public static void apply(LoggingConfiguration conf, File logbackFile) { Logback.configure(logbackFile, conf.getSubstitutionVariables()); if (conf.getLogOutput() != null) { setCustomRootAppender(conf); } }
@Test public void testCustomAppender() throws UnsupportedEncodingException { conf.setLogOutput(listener); LoggingConfigurator.apply(conf); Logger logger = LoggerFactory.getLogger(this.getClass()); logger.info(TEST_STR); assertThat(listener.msg).endsWith(TEST_STR); assertThat(listener.level).isEqualTo(LogOutput.Level.INFO); }
public static void apply(LoggingConfiguration conf, File logbackFile) { Logback.configure(logbackFile, conf.getSubstitutionVariables()); if (conf.getLogOutput() != null) { setCustomRootAppender(conf); } }
@Test public void testFormatNoEffect() throws UnsupportedEncodingException { conf.setLogOutput(listener); conf.setFormat("%t"); LoggingConfigurator.apply(conf); Logger logger = LoggerFactory.getLogger(this.getClass()); logger.info("info"); assertThat(listener.msg).isEqualTo("info"); }
@Test public void testWithFile() throws FileNotFoundException, IOException { InputStream is = this.getClass().getResourceAsStream(DEFAULT_CLASSPATH_CONF); File tmpFolder = folder.getRoot(); File testFile = new File(tmpFolder, "test"); OutputStream os = new FileOutputStream(testFile); IOUtils.copy(is, os); os.close(); conf.setLogOutput(listener); LoggingConfigurator.apply(conf, testFile); Logger logger = LoggerFactory.getLogger(this.getClass()); logger.info(TEST_STR); assertThat(listener.msg).endsWith(TEST_STR); assertThat(listener.level).isEqualTo(LogOutput.Level.INFO); }
public static void apply(LoggingConfiguration conf) { apply(conf, "/org/sonar/batch/bootstrapper/logback.xml"); }
public static void apply(LoggingConfiguration conf) { apply(conf, "/org/sonar/batch/bootstrapper/logback.xml"); }
private void configureLogging() { if (loggingConfig != null) { loggingConfig.setProperties(globalProperties); LoggingConfigurator.apply(loggingConfig); } }