Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::SolverLogger Class Reference

#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)
 

Detailed Description

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.

Note
the callbacks will get the message unchanged. No '
' will be added.

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.

Definition at line 38 of file logging.h.

Constructor & Destructor Documentation

◆ SolverLogger()

operations_research::SolverLogger::SolverLogger ( )

Definition at line 27 of file logging.cc.

Member Function Documentation

◆ AddInfoLoggingCallback()

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.

◆ ClearInfoLoggingCallbacks()

void operations_research::SolverLogger::ClearInfoLoggingCallbacks ( )

Removes all callbacks registered via AddInfoLoggingCallback().

Definition at line 34 of file logging.cc.

◆ EnableLogging()

void operations_research::SolverLogger::EnableLogging ( bool enable)
inline

Enables all logging.

Note
this is used by the logging macro, but it actually do not disable logging if LogInfo() is called directly.

Definition at line 46 of file logging.h.

◆ FlushPendingThrottledLogs()

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.

Todo
(user): If this is called too often, we could optimize it and do nothing if there are no skipped logs.

Note the -1 since we didn't skip the last log in the end.

Definition at line 79 of file logging.cc.

◆ GetNewThrottledId()

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.

◆ LoggingIsEnabled()

bool operations_research::SolverLogger::LoggingIsEnabled ( ) const
inline

Returns true iff logging is enabled.

Definition at line 49 of file logging.h.

◆ LogInfo()

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.

◆ NumInfoLoggingCallbacks()

int operations_research::SolverLogger::NumInfoLoggingCallbacks ( ) const
inline

Returns the number of registered callbacks.

Definition at line 64 of file logging.h.

◆ SetLogToStdOut()

void operations_research::SolverLogger::SetLogToStdOut ( bool enable)
inline

Should all messages be displayed on stdout ?

Definition at line 52 of file logging.h.

◆ ThrottledLog()

void operations_research::SolverLogger::ThrottledLog ( int id,
const std::string & message )

Definition at line 61 of file logging.cc.


The documentation for this class was generated from the following files: