use of com.datastax.oss.dsbulk.tests.logging.StreamType.STDERR in project dsbulk by datastax.
the class LogSettingsTest method should_log_to_main_log_file_in_verbose_mode.
@Test
void should_log_to_main_log_file_in_verbose_mode(@StreamCapture(STDERR) StreamInterceptor stdout) throws Exception {
Config config = TestConfigUtils.createTestConfig("dsbulk.log", "directory", quoteJson(customLogsDirectory), "verbosity", 2);
LogSettings settings = new LogSettings(config, executionId);
settings.init();
ch.qos.logback.classic.Logger dsbulkLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.datastax.oss.dsbulk");
assertThat(dsbulkLogger.getLevel()).isEqualTo(Level.DEBUG);
dsbulkLogger.debug("this is a test 1");
LOGGER.debug("this is a test 2");
// driver log level should now be INFO
LoggerFactory.getLogger("com.datastax.oss.driver").info("this is a test 3");
LoggerFactory.getLogger("com.datastax.oss.driver").debug("this should not appear");
LoggerFactory.getLogger("com.datastax.dse.driver").info("this is a test 4");
LoggerFactory.getLogger("com.datastax.dse.driver").debug("this should not appear");
Path logFile = customLogsDirectory.resolve(executionId).resolve("operation.log");
assertThat(logFile).exists();
List<String> contents = Files.readAllLines(logFile);
assertThat(contents).anySatisfy(line -> assertThat(line).endsWith("this is a test 1")).anySatisfy(line -> assertThat(line).endsWith("this is a test 2")).anySatisfy(line -> assertThat(line).endsWith("this is a test 3")).anySatisfy(line -> assertThat(line).endsWith("this is a test 4")).noneSatisfy(line -> assertThat(line).contains("this should not appear"));
assertThat(stdout.getStreamLinesPlain()).contains("this is a test 1", "this is a test 2", "this is a test 3", "this is a test 4").doesNotContain("this should not appear");
}
use of com.datastax.oss.dsbulk.tests.logging.StreamType.STDERR in project dsbulk by datastax.
the class LogSettingsTest method should_log_to_main_log_file_in_normal_mode.
@Test
void should_log_to_main_log_file_in_normal_mode(@StreamCapture(STDERR) StreamInterceptor stdout) throws Exception {
Config config = TestConfigUtils.createTestConfig("dsbulk.log", "directory", quoteJson(customLogsDirectory));
ch.qos.logback.classic.Logger dsbulkLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.datastax.oss.dsbulk");
Level oldLevel = dsbulkLogger.getLevel();
try {
LogSettings settings = new LogSettings(config, executionId);
settings.init();
assertThat(dsbulkLogger.getLevel()).isEqualTo(Level.INFO);
dsbulkLogger.info("this is a test 1");
dsbulkLogger.debug("this should not appear");
LOGGER.info("this is a test 2");
LOGGER.debug("this should not appear");
// driver log level should be WARN
Logger ossDriverLogger = LoggerFactory.getLogger("com.datastax.oss.driver");
ossDriverLogger.warn("this is a test 3");
ossDriverLogger.info("this should not appear");
Logger dseDriverLogger = LoggerFactory.getLogger("com.datastax.dse.driver");
dseDriverLogger.warn("this is a test 4");
dseDriverLogger.info("this should not appear");
Path logFile = customLogsDirectory.resolve(executionId).resolve("operation.log");
assertThat(logFile).exists();
List<String> contents = Files.readAllLines(logFile);
assertThat(contents).anySatisfy(line -> assertThat(line).endsWith("this is a test 1")).anySatisfy(line -> assertThat(line).endsWith("this is a test 2")).anySatisfy(line -> assertThat(line).endsWith("this is a test 3")).anySatisfy(line -> assertThat(line).endsWith("this is a test 4")).noneSatisfy(line -> assertThat(line).contains("this should not appear"));
assertThat(stdout.getStreamLinesPlain()).contains("this is a test 1", "this is a test 2", "this is a test 3", "this is a test 4").doesNotContain("this should not appear");
} finally {
dsbulkLogger.setLevel(oldLevel);
}
}
use of com.datastax.oss.dsbulk.tests.logging.StreamType.STDERR in project dsbulk by datastax.
the class LogSettingsTest method should_log_to_main_log_file_in_quiet_mode.
@Test
void should_log_to_main_log_file_in_quiet_mode(@StreamCapture(STDERR) StreamInterceptor stdout) throws Exception {
Config config = TestConfigUtils.createTestConfig("dsbulk.log", "directory", quoteJson(customLogsDirectory), "verbosity", 0);
LogSettings settings = new LogSettings(config, executionId);
settings.init();
ch.qos.logback.classic.Logger dsbulkLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.datastax.oss.dsbulk");
dsbulkLogger.warn("this is a test 1");
dsbulkLogger.info("this should not appear");
LOGGER.warn("this is a test 2");
LOGGER.info("this should not appear");
Logger ossDriverLogger = LoggerFactory.getLogger("com.datastax.oss.driver");
ossDriverLogger.warn("this is a test 3");
ossDriverLogger.info("this should not appear");
Logger dseDriverLogger = LoggerFactory.getLogger("com.datastax.dse.driver");
dseDriverLogger.warn("this is a test 4");
dseDriverLogger.info("this should not appear");
Path logFile = customLogsDirectory.resolve(executionId).resolve("operation.log");
assertThat(logFile).exists();
List<String> contents = Files.readAllLines(logFile);
assertThat(contents).anySatisfy(line -> assertThat(line).endsWith("this is a test 1")).anySatisfy(line -> assertThat(line).endsWith("this is a test 2")).anySatisfy(line -> assertThat(line).endsWith("this is a test 3")).anySatisfy(line -> assertThat(line).endsWith("this is a test 4")).noneSatisfy(line -> assertThat(line).contains("this should not appear"));
assertThat(stdout.getStreamLinesPlain()).contains("this is a test 1", "this is a test 2", "this is a test 3", "this is a test 4").doesNotContain("this should not appear");
}
Aggregations