Previously WARN level logging became FATAL level logging in the Java API (#1089)

This commit is contained in:
Adam Retter 2016-06-08 06:35:57 +01:00 committed by Yueh-Hsuan Chiang
parent a73b26f601
commit 972c895c35
2 changed files with 57 additions and 0 deletions

View File

@ -54,6 +54,9 @@ void LoggerJniCallback::Logv(const InfoLogLevel log_level,
case rocksdb::InfoLogLevel::INFO_LEVEL: case rocksdb::InfoLogLevel::INFO_LEVEL:
jlog_level = InfoLogLevelJni::INFO_LEVEL(env); jlog_level = InfoLogLevelJni::INFO_LEVEL(env);
break; break;
case rocksdb::InfoLogLevel::WARN_LEVEL:
jlog_level = InfoLogLevelJni::WARN_LEVEL(env);
break;
case rocksdb::InfoLogLevel::ERROR_LEVEL: case rocksdb::InfoLogLevel::ERROR_LEVEL:
jlog_level = InfoLogLevelJni::ERROR_LEVEL(env); jlog_level = InfoLogLevelJni::ERROR_LEVEL(env);
break; break;

View File

@ -48,6 +48,36 @@ public class LoggerTest {
} }
} }
@Test
public void warnLogger() throws RocksDBException {
final AtomicInteger logMessageCounter = new AtomicInteger();
try (final Options options = new Options().
setInfoLogLevel(InfoLogLevel.WARN_LEVEL).
setCreateIfMissing(true);
final Logger logger = new Logger(options) {
// Create new logger with max log level passed by options
@Override
protected void log(InfoLogLevel infoLogLevel, String logMsg) {
assertThat(logMsg).isNotNull();
assertThat(logMsg.length()).isGreaterThan(0);
logMessageCounter.incrementAndGet();
}
}
) {
// Set custom logger to options
options.setLogger(logger);
try (final RocksDB db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath())) {
// there should be zero messages
// using warn level as log level.
assertThat(logMessageCounter.get()).isEqualTo(0);
}
}
}
@Test @Test
public void fatalLogger() throws RocksDBException { public void fatalLogger() throws RocksDBException {
@ -119,6 +149,30 @@ public class LoggerTest {
} }
} }
@Test
public void setWarnLogLevel() {
final AtomicInteger logMessageCounter = new AtomicInteger();
try (final Options options = new Options().
setInfoLogLevel(InfoLogLevel.FATAL_LEVEL).
setCreateIfMissing(true);
final Logger logger = new Logger(options) {
// Create new logger with max log level passed by options
@Override
protected void log(InfoLogLevel infoLogLevel, String logMsg) {
assertThat(logMsg).isNotNull();
assertThat(logMsg.length()).isGreaterThan(0);
logMessageCounter.incrementAndGet();
}
}
) {
assertThat(logger.infoLogLevel()).
isEqualTo(InfoLogLevel.FATAL_LEVEL);
logger.setInfoLogLevel(InfoLogLevel.WARN_LEVEL);
assertThat(logger.infoLogLevel()).
isEqualTo(InfoLogLevel.WARN_LEVEL);
}
}
@Test @Test
public void setInfoLogLevel() { public void setInfoLogLevel() {
final AtomicInteger logMessageCounter = new AtomicInteger(); final AtomicInteger logMessageCounter = new AtomicInteger();