diff options
author | 2018-03-21 15:32:30 -0700 | |
---|---|---|
committer | 2018-03-21 15:33:51 -0700 | |
commit | 9eea0f9a98c6bec344284bfecc7c91c9d8dd7715 (patch) | |
tree | 1b3ca4173ff215bfa0651b7614cbfd056ed71cb1 /src/main/cpp/util/logging.cc | |
parent | b12892e0ca50a436f1e629ec4391ee4068623dc6 (diff) |
Update the client's skeleton logging framework to use it for --client_debug.
We are still unable to turn this on to write to files, but there are currently 2 logging systems in use in the client: the inactive one, and the print-to-stderr option triggered by --client_debug. Combine these, so we can use the same logging format for both.
Also combine it with the VerboseLogging functionality - it was not documented anywhere and seems redundant.
RELNOTES: None.
PiperOrigin-RevId: 189979051
Diffstat (limited to 'src/main/cpp/util/logging.cc')
-rw-r--r-- | src/main/cpp/util/logging.cc | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/main/cpp/util/logging.cc b/src/main/cpp/util/logging.cc index 7d0bd0bfd0..8ae4b5dbb3 100644 --- a/src/main/cpp/util/logging.cc +++ b/src/main/cpp/util/logging.cc @@ -23,9 +23,10 @@ namespace blaze_util { const char* LogLevelName(LogLevel level) { - static const char* level_names[] = {"INFO", "WARNING", "ERROR", "FATAL"}; - BAZEL_CHECK(static_cast<int>(level) < 4) - << "LogLevelName: level out of range, there are only 4 levels."; + static const char* level_names[] = {"INFO", "USER", "WARNING", "ERROR", + "FATAL"}; + BAZEL_CHECK(static_cast<int>(level) < 5) + << "LogLevelName: level out of range, there are only 5 levels."; return level_names[level]; } @@ -64,6 +65,10 @@ void LogMessage::Finish() { std::string message(message_.str()); if (log_handler_ != nullptr) { log_handler_->HandleMessage(level_, filename_, line_, message); + } else if (level_ == LOGLEVEL_USER) { + // Messages directed at the user should be printed even without a log + // handler. + std::cerr << message << std::endl; } else if (level_ == LOGLEVEL_FATAL) { // Expect the log_handler_ to handle FATAL calls, but we should still fail // as expected even if no log_handler_ is defined. For ease of debugging, @@ -82,9 +87,14 @@ void SetLogHandler(std::unique_ptr<LogHandler> new_handler) { internal::log_handler_ = std::move(new_handler); } -void SetLogfileDirectory(const std::string& output_dir) { +void SetLoggingOutputStream(std::unique_ptr<std::ostream> output_stream) { if (internal::log_handler_ != nullptr) { - internal::log_handler_->SetOutputDir(output_dir); + internal::log_handler_->SetOutputStream(std::move(output_stream)); + } +} +void SetLoggingOutputStreamToStderr() { + if (internal::log_handler_ != nullptr) { + internal::log_handler_->SetOutputStreamToStderr(); } } |