private Batch(Builder builder) { components = new ArrayList<>(); components.addAll(builder.components); if (builder.environment != null) { components.add(builder.environment); } if (builder.globalProperties != null) { globalProperties.putAll(builder.globalProperties); } if (builder.isEnableLoggingConfiguration()) { loggingConfig = new LoggingConfiguration(builder.environment).setProperties(globalProperties); if (builder.logOutput != null) { loggingConfig.setLogOutput(builder.logOutput); } } }
public LoggingConfiguration(@Nullable EnvironmentInformation environment) { setVerbose(false); if (environment != null && "maven".equalsIgnoreCase(environment.getKey())) { setFormat(FORMAT_MAVEN); } else { setFormat(FORMAT_DEFAULT); } }
@Test public void testSetVerbose() { assertThat(new LoggingConfiguration(null).setVerbose(true) .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_VERBOSE); assertThat(new LoggingConfiguration(null).setVerbose(false) .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT); assertThat(new LoggingConfiguration(null).setRootLevel("ERROR") .getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo("ERROR"); }
public static void apply(LoggingConfiguration conf, File logbackFile) { Logback.configure(logbackFile, conf.getSubstitutionVariables()); if (conf.getLogOutput() != null) { setCustomRootAppender(conf); } }
@Test public void testSetVerboseAnalysis() { Map<String, String> props = Maps.newHashMap(); LoggingConfiguration conf = new LoggingConfiguration(null).setProperties(props); assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT); props.put("sonar.verbose", "true"); conf.setProperties(props); assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_VERBOSE); }
@Test public void test_log_listener_setter() { LogOutput listener = mock(LogOutput.class); assertThat(new LoggingConfiguration(null).setLogOutput(listener).getLogOutput()).isEqualTo(listener); }
@Test public void shouldNotSetBlankFormat() { assertThat(new LoggingConfiguration(null).setFormat(null) .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT); assertThat(new LoggingConfiguration(null).setFormat("") .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT); assertThat(new LoggingConfiguration(null).setFormat(" ") .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT); } }
public LoggingConfiguration setRootLevel(String level) { return addSubstitutionVariable(PROPERTY_ROOT_LOGGER_LEVEL, level); }
public LoggingConfiguration setProperties(Map<String, String> properties) { setShowSql(properties, null); setVerbose(properties, null); return this; }
@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 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"); }
@Test public void testDefaultFormat() { assertThat(new LoggingConfiguration(null) .getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT); }
public LoggingConfiguration setProperties(Map<String, String> properties) { setVerbose(properties); return this; }
private void configureLogging() { if (loggingConfig != null) { loggingConfig.setProperties(globalProperties); LoggingConfigurator.apply(loggingConfig); } }
public LoggingConfiguration setVerbose(boolean verbose) { return setRootLevel(verbose ? LEVEL_ROOT_VERBOSE : LEVEL_ROOT_DEFAULT); }
@Before public void setUp() { out = new ByteArrayOutputStream(); conf = new LoggingConfiguration(); listener = new SimpleLogListener(); }
@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 LoggingConfiguration setVerbose(Map<String, String> props, @Nullable Map<String, String> fallback) { String logLevel = getFallback("sonar.log.level", props, fallback); String deprecatedProfilingLevel = getFallback("sonar.log.profilingLevel", props, fallback); verbose = "true".equals(getFallback("sonar.verbose", props, fallback)) || "DEBUG".equals(logLevel) || "TRACE".equals(logLevel) || "BASIC".equals(deprecatedProfilingLevel) || "FULL".equals(deprecatedProfilingLevel); return setVerbose(verbose); }
private Batch(Builder builder) { components = Lists.newArrayList(); components.addAll(builder.components); if (builder.environment != null) { components.add(builder.environment); } if (builder.bootstrapProperties != null) { bootstrapProperties.putAll(builder.bootstrapProperties); } if (builder.isEnableLoggingConfiguration()) { logging = LoggingConfiguration.create(builder.environment).setProperties(bootstrapProperties); } }
private RuntimeException handleException(RuntimeException t) { if (loggingConfig.isVerbose()) { return t; } for (Throwable y : Throwables.getCausalChain(t)) { if (y instanceof MessageException) { return (MessageException) y; } } return t; }