logger#
#include <raft/core/logger.hpp>
namespace raft::core
-
class logger#
The main Logging class for raft library.
This class acts as a thin wrapper over the underlying
spdlog
interface. The design is done in this way in order to avoid us having to also shipspdlog
header files in our installation.- Todo:
This currently only supports logging to stdout. Need to add support in future to add custom loggers as well [Issue #2046]
Public Functions
-
void set_level(int level)#
Set the logging level.
Only messages with level equal or above this will be printed
Note
The log level will actually be set only if the input is within the range [RAFT_LEVEL_TRACE, RAFT_LEVEL_OFF]. If it is not, then it’ll be ignored. See documentation of decisiontree for how this gets used
- Parameters:
level – [in] logging level
-
void set_pattern(const std::string &pattern)#
Set the logging pattern.
- Parameters:
pattern – [in] the pattern to be set. Refer this link gabime/spdlog to know the right syntax of this pattern
-
void set_callback(void (*callback)(int lvl, const char *msg))#
Register a callback function to be run in place of usual log call.
- Parameters:
callback – [in] the function to be run on all logged messages
-
void set_flush(void (*flush)())#
Register a flush function compatible with the registered callback.
- Parameters:
flush – [in] the function to use when flushing logs
-
bool should_log_for(int level) const#
Tells whether messages will be logged for the given log level.
- Parameters:
level – [in] log level to be checked for
- Returns:
true if messages will be logged for this level, else false
-
int get_level() const#
Query for the current log level.
- Returns:
the current log level
-
std::string get_pattern() const#
Get the current logging pattern.
- Returns:
the pattern
-
void log(int level, const char *fmt, ...)#
Main logging method.
- Parameters:
level – [in] logging level of this message
fmt – [in] C-like format string, followed by respective params
-
void flush()#
Flush logs by calling flush on underlying logger.
Public Static Functions
-
class impl#