23#include "absl/strings/str_cat.h"
31 info_callbacks_.push_back(std::move(
callback));
39 std::cout <<
message << std::endl;
42 for (
const auto&
callback : info_callbacks_) {
48 const int id = id_to_throttling_data_.size();
49 id_to_throttling_data_.resize(
id + 1);
53bool SolverLogger::RateIsOk(
const ThrottlingData& data) {
54 const double time = std::max(1.0, timer_.
Get());
56 static_cast<double>(data.num_displayed_logs - throttling_threshold_) /
58 return rate < throttling_rate_;
62 if (!is_enabled_)
return;
63 ThrottlingData& data = id_to_throttling_data_[id];
65 if (data.num_last_skipped_logs > 0) {
68 " [skipped_logs=", data.num_last_skipped_logs,
"]"));
72 data.UpdateWhenDisplayed();
74 data.num_last_skipped_logs++;
75 data.last_skipped_message =
message;
80 if (!is_enabled_)
return;
84 for (
int id = 0;
id < id_to_throttling_data_.size(); ++id) {
85 ThrottlingData& data = id_to_throttling_data_[id];
86 if (data.num_last_skipped_logs == 0)
continue;
87 if (ignore_rates || RateIsOk(data)) {
90 absl::StrCat(data.last_skipped_message,
" [skipped_logs=",
91 data.num_last_skipped_logs - 1,
"]"));
92 data.UpdateWhenDisplayed();
void Start()
When Start() is called multiple times, only the most recent is used.
void ThrottledLog(int id, const std::string &message)
void FlushPendingThrottledLogs(bool ignore_rates=false)
void AddInfoLoggingCallback(std::function< void(const std::string &message)> callback)
void ClearInfoLoggingCallbacks()
Removes all callbacks registered via AddInfoLoggingCallback().
void LogInfo(const char *source_filename, int source_line, const std::string &message)
Logs a given information message and dispatch it to all callbacks.
In SWIG mode, we don't want anything besides these top-level includes.