diff --git a/tools/ldb_cmd.cc b/tools/ldb_cmd.cc index 2f4c3e2ad..d3781e3f6 100644 --- a/tools/ldb_cmd.cc +++ b/tools/ldb_cmd.cc @@ -12,19 +12,20 @@ #include -#include "db/dbformat.h" #include "db/db_impl.h" -#include "db/log_reader.h" +#include "db/dbformat.h" #include "db/filename.h" -#include "db/writebuffer.h" +#include "db/log_reader.h" #include "db/write_batch_internal.h" -#include "rocksdb/write_batch.h" +#include "db/writebuffer.h" +#include "port/dirent.h" #include "rocksdb/cache.h" #include "rocksdb/table_properties.h" +#include "rocksdb/write_batch.h" #include "table/scoped_arena_iterator.h" -#include "port/dirent.h" #include "tools/sst_dump_tool_imp.h" #include "util/coding.h" +#include "util/stderr_logger.h" #include "util/string_util.h" #include "utilities/ttl/db_ttl_impl.h" @@ -2159,6 +2160,7 @@ void RepairCommand::Help(string& ret) { void RepairCommand::DoCommand() { Options options = PrepareOptionsForOpenDB(); + options.info_log.reset(new StderrLogger(InfoLogLevel::WARN_LEVEL)); Status status = RepairDB(db_path_, options); if (status.ok()) { printf("OK\n"); diff --git a/util/options_test.cc b/util/options_test.cc index bb5cc96e4..aaa585523 100644 --- a/util/options_test.cc +++ b/util/options_test.cc @@ -24,6 +24,7 @@ #include "util/options_parser.h" #include "util/options_sanity_check.h" #include "util/random.h" +#include "util/stderr_logger.h" #include "util/testharness.h" #include "util/testutil.h" @@ -37,15 +38,6 @@ DEFINE_bool(enable_print, false, "Print options generated to console."); namespace rocksdb { -class StderrLogger : public Logger { - public: - using Logger::Logv; - virtual void Logv(const char* format, va_list ap) override { - vprintf(format, ap); - printf("\n"); - } -}; - Options PrintAndGetOptions(size_t total_write_buffer_limit, int read_amplification_threshold, int write_amplification_threshold, diff --git a/util/stderr_logger.h b/util/stderr_logger.h new file mode 100644 index 000000000..1258d34a2 --- /dev/null +++ b/util/stderr_logger.h @@ -0,0 +1,31 @@ +// Copyright (c) 2016-present, Facebook, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory. + +#pragma once + +#include +#include + +#include "rocksdb/env.h" + +namespace rocksdb { + +// Prints logs to stderr for faster debugging +class StderrLogger : public Logger { + public: + explicit StderrLogger(const InfoLogLevel log_level = InfoLogLevel::INFO_LEVEL) + : Logger(log_level) {} + + // Brings overloaded Logv()s into scope so they're not hidden when we override + // a subset of them. + using Logger::Logv; + + virtual void Logv(const char* format, va_list ap) override { + vfprintf(stderr, format, ap); + fprintf(stderr, "\n"); + } +}; + +} // namespace rocksdb