Public Member Functions | Static Public Member Functions | List of all members
ML::Logger Class Reference

The main Logging class for cuML library. More...

#include <logger.hpp>

Collaboration diagram for ML::Logger:
Collaboration graph

Public Member Functions

void setLevel (int level)
 Set the logging level. More...
 
void setPattern (const std::string &pattern)
 Set the logging pattern. More...
 
void setCallback (void(*callback)(int lvl, const char *msg))
 Register a callback function to be run in place of usual log call. More...
 
void setFlush (void(*flush)())
 Register a flush function compatible with the registered callback. More...
 
bool shouldLogFor (int level) const
 Tells whether messages will be logged for the given log level. More...
 
int getLevel () const
 Query for the current log level. More...
 
std::string getPattern () const
 Get the current logging pattern. More...
 
void log (int level, const char *fmt,...)
 Main logging method. More...
 
void flush ()
 Flush logs by calling flush on underlying logger. More...
 

Static Public Member Functions

static Loggerget ()
 Singleton method to get the underlying logger object. More...
 

Detailed Description

The main Logging class for cuML 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 ship spdlog 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]

Member Function Documentation

◆ flush()

void ML::Logger::flush ( )

Flush logs by calling flush on underlying logger.

◆ get()

Logger & ML::Logger::get ( )
static

Singleton method to get the underlying logger object.

Returns
the singleton logger object

◆ getLevel()

int ML::Logger::getLevel ( ) const

Query for the current log level.

Returns
the current log level

◆ getPattern()

std::string ML::Logger::getPattern ( ) const
inline

Get the current logging pattern.

Returns
the pattern

◆ log()

void ML::Logger::log ( int  level,
const char *  fmt,
  ... 
)

Main logging method.

Parameters
[in]levellogging level of this message
[in]fmtC-like format string, followed by respective params

◆ setCallback()

void ML::Logger::setCallback ( void(*)(int lvl, const char *msg)  callback)

Register a callback function to be run in place of usual log call.

Parameters
[in]callbackthe function to be run on all logged messages

◆ setFlush()

void ML::Logger::setFlush ( void(*)()  flush)

Register a flush function compatible with the registered callback.

Parameters
[in]flushthe function to use when flushing logs

◆ setLevel()

void ML::Logger::setLevel ( int  level)

Set the logging level.

Only messages with level equal or above this will be printed

Parameters
[in]levellogging level
Note
The log level will actually be set only if the input is within the range [CUML_LEVEL_TRACE, CUML_LEVEL_OFF]. If it is not, then it'll be ignored. See documentation of decisiontree for how this gets used

◆ setPattern()

void ML::Logger::setPattern ( const std::string &  pattern)

Set the logging pattern.

Parameters
[in]patternthe pattern to be set. Refer this link https://github.com/gabime/spdlog/wiki/3.-Custom-formatting to know the right syntax of this pattern

◆ shouldLogFor()

bool ML::Logger::shouldLogFor ( int  level) const

Tells whether messages will be logged for the given log level.

Parameters
[in]levellog level to be checked for
Returns
true if messages will be logged for this level, else false

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