diff options
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(); } } |