22#include "absl/strings/str_cat.h"
38 std::cout <<
message << std::endl;
41 for (
const auto&
callback : info_callbacks_) {
47 const int id = id_to_throttling_data_.size();
48 id_to_throttling_data_.resize(
id + 1);
52bool SolverLogger::RateIsOk(
const ThrottlingData& data) {
53 const double time = std::max(1.0, timer_.
Get());
55 static_cast<double>(data.num_displayed_logs - throttling_threshold_) /
57 return rate < throttling_rate_;
61 if (!is_enabled_)
return;
62 ThrottlingData& data = id_to_throttling_data_[id];
64 if (data.num_last_skipped_logs > 0) {
67 " [skipped_logs=", data.num_last_skipped_logs,
"]"));
71 data.UpdateWhenDisplayed();
73 data.num_last_skipped_logs++;
74 data.last_skipped_message =
message;
79 if (!is_enabled_)
return;
83 for (
int id = 0;
id < id_to_throttling_data_.size(); ++id) {
84 ThrottlingData& data = id_to_throttling_data_[id];
85 if (data.num_last_skipped_logs == 0)
continue;
86 if (ignore_rates || RateIsOk(data)) {
89 absl::StrCat(data.last_skipped_message,
" [skipped_logs=",
90 data.num_last_skipped_logs - 1,
"]"));
91 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.