public final class LoggingConfiguration {
public static final String PROPERTY_ROOT_LOGGER_LEVEL = "ROOT_LOGGER_LEVEL";
- public static final String PROPERTY_SQL_LOGGER_LEVEL = "SQL_LOGGER_LEVEL";
public static final String PROPERTY_SQL_RESULTS_LOGGER_LEVEL = "SQL_RESULTS_LOGGER_LEVEL";
public static final String PROPERTY_FORMAT = "FORMAT";
private LoggingConfiguration(@Nullable EnvironmentInformation environment) {
setVerbose(false);
- setShowSql(false);
if (environment != null && "maven".equalsIgnoreCase(environment.getKey())) {
setFormat(FORMAT_MAVEN);
} else {
public LoggingConfiguration setProperties(Map<String, String> properties) {
Profiling.Level profilingLevel = Profiling.Level.fromConfigString(properties.get("sonar.log.profilingLevel"));
- setShowSql(profilingLevel == Level.FULL);
setShowSqlResults(profilingLevel == Level.FULL);
setVerbose("true".equals(properties.get("sonar.verbose")));
return this;
return setRootLevel(verbose ? LEVEL_ROOT_VERBOSE : LEVEL_ROOT_DEFAULT);
}
- public LoggingConfiguration setShowSql(boolean showSql) {
- return setSqlLevel(showSql ? LEVEL_SQL_VERBOSE : LEVEL_SQL_DEFAULT);
- }
-
public LoggingConfiguration setShowSqlResults(boolean showSqlResults) {
return setSqlResultsLevel(showSqlResults ? LEVEL_SQL_RESULTS_VERBOSE : LEVEL_SQL_RESULTS_DEFAULT);
}
return addSubstitutionVariable(PROPERTY_ROOT_LOGGER_LEVEL, level);
}
- public LoggingConfiguration setSqlLevel(String level) {
- return addSubstitutionVariable(PROPERTY_SQL_LOGGER_LEVEL, level);
- }
-
public LoggingConfiguration setSqlResultsLevel(String level) {
return addSubstitutionVariable(PROPERTY_SQL_RESULTS_LOGGER_LEVEL, level);
}
<!-- sonar.showSql -->
<!-- see also org.sonar.core.persistence.MyBatis#configureLogback() -->
<logger name="org.hibernate.SQL">
- <level value="${SQL_LOGGER_LEVEL:-ERROR}"/>
+ <level value="ERROR"/>
</logger>
<logger name="org.apache.ibatis">
- <level value="${SQL_LOGGER_LEVEL:-WARN}"/>
+ <level value="WARN"/>
</logger>
<logger name="org.mybatis">
- <level value="${SQL_LOGGER_LEVEL:-WARN}"/>
+ <level value="WARN"/>
</logger>
<logger name="java.sql">
- <level value="${SQL_LOGGER_LEVEL:-WARN}"/>
+ <level value="WARN"/>
</logger>
<logger name="java.sql.ResultSet">
<level value="${SQL_RESULTS_LOGGER_LEVEL:-WARN}"/>
public class LoggingConfigurationTest {
- @Test
- public void testSqlLevel() {
- assertThat(LoggingConfiguration.create(null).setShowSql(true)
- .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_VERBOSE);
-
- assertThat(LoggingConfiguration.create(null).setShowSql(false)
- .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT);
-
- assertThat(LoggingConfiguration.create(null).setSqlLevel("ERROR")
- .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo("ERROR");
- }
-
- @Test
- public void shouldNotShowSqlByDefault() {
- assertThat(LoggingConfiguration.create(null)
- .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT);
- }
-
@Test
public void testSetVerbose() {
assertThat(LoggingConfiguration.create(null).setVerbose(true)
public void testSetShowSqlProperty() {
Map<String, String> properties = Maps.newHashMap();
assertThat(LoggingConfiguration.create(null).setProperties(properties)
- .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT);
+ .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_RESULTS_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT);
properties.put("sonar.log.profilingLevel", "FULL");
assertThat(LoggingConfiguration.create(null).setProperties(properties)
- .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_VERBOSE);
+ .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_RESULTS_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_VERBOSE);
properties.put("sonar.log.profilingLevel", "BASIC");
assertThat(LoggingConfiguration.create(null).setProperties(properties)
- .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT);
+ .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_RESULTS_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT);
properties.put("sonar.log.profilingLevel", "NONE");
assertThat(LoggingConfiguration.create(null).setProperties(properties)
- .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT);
+ .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_RESULTS_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT);
}
@Test