Search in sources :

Example 1 with StreamInterceptor

use of com.datastax.oss.dsbulk.tests.logging.StreamInterceptor 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");
}
Also used : Path(java.nio.file.Path) StreamCapture(com.datastax.oss.dsbulk.tests.logging.StreamCapture) BeforeEach(org.junit.jupiter.api.BeforeEach) LogUtils(com.datastax.oss.dsbulk.tests.logging.LogUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DriverUtils(com.datastax.oss.dsbulk.tests.driver.DriverUtils) LoggerFactory(org.slf4j.LoggerFactory) RatioErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.RatioErrorThreshold) ErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.ErrorThreshold) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Path(java.nio.file.Path) AbsoluteErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.AbsoluteErrorThreshold) StreamInterceptor(com.datastax.oss.dsbulk.tests.logging.StreamInterceptor) FileUtils(com.datastax.oss.dsbulk.tests.utils.FileUtils) Logger(org.slf4j.Logger) Config(com.typesafe.config.Config) Files(java.nio.file.Files) StringUtils.quoteJson(com.datastax.oss.dsbulk.tests.utils.StringUtils.quoteJson) IOException(java.io.IOException) UnlimitedErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.UnlimitedErrorThreshold) Test(org.junit.jupiter.api.Test) StreamInterceptingExtension(com.datastax.oss.dsbulk.tests.logging.StreamInterceptingExtension) Level(ch.qos.logback.classic.Level) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Paths(java.nio.file.Paths) JoranException(ch.qos.logback.core.joran.spi.JoranException) TestConfigUtils(com.datastax.oss.dsbulk.tests.utils.TestConfigUtils) STDERR(com.datastax.oss.dsbulk.tests.logging.StreamType.STDERR) LogManager(com.datastax.oss.dsbulk.workflow.commons.log.LogManager) BeforeEach(org.junit.jupiter.api.BeforeEach) AfterEach(org.junit.jupiter.api.AfterEach) Config(com.typesafe.config.Config) Logger(org.slf4j.Logger) Test(org.junit.jupiter.api.Test)

Example 2 with StreamInterceptor

use of com.datastax.oss.dsbulk.tests.logging.StreamInterceptor 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);
    }
}
Also used : Path(java.nio.file.Path) StreamCapture(com.datastax.oss.dsbulk.tests.logging.StreamCapture) BeforeEach(org.junit.jupiter.api.BeforeEach) LogUtils(com.datastax.oss.dsbulk.tests.logging.LogUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DriverUtils(com.datastax.oss.dsbulk.tests.driver.DriverUtils) LoggerFactory(org.slf4j.LoggerFactory) RatioErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.RatioErrorThreshold) ErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.ErrorThreshold) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Path(java.nio.file.Path) AbsoluteErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.AbsoluteErrorThreshold) StreamInterceptor(com.datastax.oss.dsbulk.tests.logging.StreamInterceptor) FileUtils(com.datastax.oss.dsbulk.tests.utils.FileUtils) Logger(org.slf4j.Logger) Config(com.typesafe.config.Config) Files(java.nio.file.Files) StringUtils.quoteJson(com.datastax.oss.dsbulk.tests.utils.StringUtils.quoteJson) IOException(java.io.IOException) UnlimitedErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.UnlimitedErrorThreshold) Test(org.junit.jupiter.api.Test) StreamInterceptingExtension(com.datastax.oss.dsbulk.tests.logging.StreamInterceptingExtension) Level(ch.qos.logback.classic.Level) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Paths(java.nio.file.Paths) JoranException(ch.qos.logback.core.joran.spi.JoranException) TestConfigUtils(com.datastax.oss.dsbulk.tests.utils.TestConfigUtils) STDERR(com.datastax.oss.dsbulk.tests.logging.StreamType.STDERR) LogManager(com.datastax.oss.dsbulk.workflow.commons.log.LogManager) BeforeEach(org.junit.jupiter.api.BeforeEach) AfterEach(org.junit.jupiter.api.AfterEach) Config(com.typesafe.config.Config) Logger(org.slf4j.Logger) Level(ch.qos.logback.classic.Level) Test(org.junit.jupiter.api.Test)

Example 3 with StreamInterceptor

use of com.datastax.oss.dsbulk.tests.logging.StreamInterceptor 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");
}
Also used : Path(java.nio.file.Path) StreamCapture(com.datastax.oss.dsbulk.tests.logging.StreamCapture) BeforeEach(org.junit.jupiter.api.BeforeEach) LogUtils(com.datastax.oss.dsbulk.tests.logging.LogUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DriverUtils(com.datastax.oss.dsbulk.tests.driver.DriverUtils) LoggerFactory(org.slf4j.LoggerFactory) RatioErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.RatioErrorThreshold) ErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.ErrorThreshold) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Path(java.nio.file.Path) AbsoluteErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.AbsoluteErrorThreshold) StreamInterceptor(com.datastax.oss.dsbulk.tests.logging.StreamInterceptor) FileUtils(com.datastax.oss.dsbulk.tests.utils.FileUtils) Logger(org.slf4j.Logger) Config(com.typesafe.config.Config) Files(java.nio.file.Files) StringUtils.quoteJson(com.datastax.oss.dsbulk.tests.utils.StringUtils.quoteJson) IOException(java.io.IOException) UnlimitedErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.UnlimitedErrorThreshold) Test(org.junit.jupiter.api.Test) StreamInterceptingExtension(com.datastax.oss.dsbulk.tests.logging.StreamInterceptingExtension) Level(ch.qos.logback.classic.Level) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Paths(java.nio.file.Paths) JoranException(ch.qos.logback.core.joran.spi.JoranException) TestConfigUtils(com.datastax.oss.dsbulk.tests.utils.TestConfigUtils) STDERR(com.datastax.oss.dsbulk.tests.logging.StreamType.STDERR) LogManager(com.datastax.oss.dsbulk.workflow.commons.log.LogManager) BeforeEach(org.junit.jupiter.api.BeforeEach) AfterEach(org.junit.jupiter.api.AfterEach) Config(com.typesafe.config.Config) Logger(org.slf4j.Logger) Test(org.junit.jupiter.api.Test)

Aggregations

Level (ch.qos.logback.classic.Level)3 JoranException (ch.qos.logback.core.joran.spi.JoranException)3 CqlSession (com.datastax.oss.driver.api.core.CqlSession)3 DriverUtils (com.datastax.oss.dsbulk.tests.driver.DriverUtils)3 LogUtils (com.datastax.oss.dsbulk.tests.logging.LogUtils)3 StreamCapture (com.datastax.oss.dsbulk.tests.logging.StreamCapture)3 StreamInterceptingExtension (com.datastax.oss.dsbulk.tests.logging.StreamInterceptingExtension)3 StreamInterceptor (com.datastax.oss.dsbulk.tests.logging.StreamInterceptor)3 STDERR (com.datastax.oss.dsbulk.tests.logging.StreamType.STDERR)3 FileUtils (com.datastax.oss.dsbulk.tests.utils.FileUtils)3 StringUtils.quoteJson (com.datastax.oss.dsbulk.tests.utils.StringUtils.quoteJson)3 TestConfigUtils (com.datastax.oss.dsbulk.tests.utils.TestConfigUtils)3 AbsoluteErrorThreshold (com.datastax.oss.dsbulk.workflow.api.error.AbsoluteErrorThreshold)3 ErrorThreshold (com.datastax.oss.dsbulk.workflow.api.error.ErrorThreshold)3 RatioErrorThreshold (com.datastax.oss.dsbulk.workflow.api.error.RatioErrorThreshold)3 UnlimitedErrorThreshold (com.datastax.oss.dsbulk.workflow.api.error.UnlimitedErrorThreshold)3 LogManager (com.datastax.oss.dsbulk.workflow.commons.log.LogManager)3 Config (com.typesafe.config.Config)3 IOException (java.io.IOException)3 Files (java.nio.file.Files)3