Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <logging.h>
Public Member Functions | |
SolverLogger () | |
void | EnableLogging (bool enable) |
bool | LoggingIsEnabled () const |
Returns true iff logging is enabled. | |
void | SetLogToStdOut (bool enable) |
Should all messages be displayed on stdout ? | |
void | AddInfoLoggingCallback (std::function< void(const std::string &message)> callback) |
void | ClearInfoLoggingCallbacks () |
Removes all callbacks registered via AddInfoLoggingCallback(). | |
int | NumInfoLoggingCallbacks () const |
Returns the number of registered callbacks. | |
void | LogInfo (const char *source_filename, int source_line, const std::string &message) |
Logs a given information message and dispatch it to all callbacks. | |
int | GetNewThrottledId () |
void | ThrottledLog (int id, const std::string &message) |
void | FlushPendingThrottledLogs (bool ignore_rates=false) |
Custom logger class. It allows passing callbacks to process log messages.
If no callbacks have been added, all logging will use the standard logging facilities. As soon as one callback is added, it is disabled. Unless ForceStandardLogging() has been called.
Important: This class is currently not thread-safe, it is easy to add a mutex if needed. In CP-SAT, we currently make sure all access to this class do not happen concurrently.
operations_research::SolverLogger::SolverLogger | ( | ) |
Definition at line 27 of file logging.cc.
void operations_research::SolverLogger::AddInfoLoggingCallback | ( | std::function< void(const std::string &message)> | callback | ) |
Add a callback listening to all information messages.
They will be run synchronously when LogInfo() is called.
Definition at line 29 of file logging.cc.
void operations_research::SolverLogger::ClearInfoLoggingCallbacks | ( | ) |
Removes all callbacks registered via AddInfoLoggingCallback().
Definition at line 34 of file logging.cc.
|
inline |
void operations_research::SolverLogger::FlushPendingThrottledLogs | ( | bool | ignore_rates = false | ) |
To not loose the last message of a throttled log, we keep it in memory and when this function is called we flush logs whose rate is now under the limit.
Note the -1 since we didn't skip the last log in the end.
Definition at line 79 of file logging.cc.
int operations_research::SolverLogger::GetNewThrottledId | ( | ) |
Facility to avoid having multi megabytes logs when it brings little benefits. Logs with the same id will be kept under an average of throttling_rate_ logs per second.
Definition at line 47 of file logging.cc.
|
inline |
void operations_research::SolverLogger::LogInfo | ( | const char * | source_filename, |
int | source_line, | ||
const std::string & | message ) |
Logs a given information message and dispatch it to all callbacks.
Definition at line 36 of file logging.cc.
|
inline |
|
inline |
void operations_research::SolverLogger::ThrottledLog | ( | int | id, |
const std::string & | message ) |
Definition at line 61 of file logging.cc.