Fledge
An open source edge computing platform for industrial users
Logger Class Reference

Fledge Logger class used to log to syslog. More...

#include <logger.h>

Public Types

enum  LogLevel {
  ERROR, WARNING, INFO, DEBUG,
  FATAL
}
 
typedef void(* LogInterceptor) (LogLevel, const std::string &, void *)
 

Public Member Functions

 Logger (const std::string &application)
 Constructor for the Logger class. More...
 
 ~Logger ()
 Destructor for the logger class.
 
void debug (const std::string &msg,...)
 Log a message at the level debug. More...
 
void printLongString (const std::string &, LogLevel=LogLevel::DEBUG)
 Log a long string across multiple syslog entries. More...
 
void info (const std::string &msg,...)
 Log a message at the level info. More...
 
void warn (const std::string &msg,...)
 Log a message at the level warn. More...
 
void error (const std::string &msg,...)
 Log a message at the level error. More...
 
void fatal (const std::string &msg,...)
 Log a message at the level fatal. More...
 
void setMinLevel (const std::string &level)
 Set the minimum level of logging to write to syslog. More...
 
std::string & getMinLevel ()
 
bool registerInterceptor (LogLevel level, LogInterceptor callback, void *userData)
 Register a callback function to be called when a log message is written that matches the specification given. More...
 
bool unregisterInterceptor (LogLevel level, LogInterceptor callback)
 Remove the registration of a previously registered callback. More...
 

Static Public Member Functions

static LoggergetLogger ()
 Return the singleton instance of the logger class.
 

Detailed Description

Fledge Logger class used to log to syslog.

At startup this class should be constructed using the standard constructor. To log a message call debug, info, warn etc. using the instance of the class.

To obtain that singleton instance call the static method getLogger.

It is generally unsafe to delete the logger class as it may be called asynchronouly from multiple threads and single handlers. The destructor has hence been made private to prevent the destruction of the class.

Constructor & Destructor Documentation

◆ Logger()

Logger::Logger ( const std::string &  application)

Constructor for the Logger class.

Parameters
applicationThe application name

Member Function Documentation

◆ debug()

void Logger::debug ( const std::string &  msg,
  ... 
)

Log a message at the level debug.

Parameters
msgA printf format string
...The variable arguments required by the printf format

◆ error()

void Logger::error ( const std::string &  msg,
  ... 
)

Log a message at the level error.

Parameters
msgA printf format string
...The variable arguments required by the printf format

◆ fatal()

void Logger::fatal ( const std::string &  msg,
  ... 
)

Log a message at the level fatal.

Parameters
msgA printf format string
...The variable arguments required by the printf format

◆ info()

void Logger::info ( const std::string &  msg,
  ... 
)

Log a message at the level info.

Parameters
msgA printf format string
...The variable arguments required by the printf format

◆ printLongString()

void Logger::printLongString ( const std::string &  ,
LogLevel  = LogLevel::DEBUG 
)

Log a long string across multiple syslog entries.

Parameters
sThe string to log
levellevel to log the string at

◆ registerInterceptor()

bool Logger::registerInterceptor ( LogLevel  level,
LogInterceptor  callback,
void *  userData 
)

Register a callback function to be called when a log message is written that matches the specification given.

Note: The callback functions are called on a separate thread. This worker thread is only created when the first callback is registered.

Parameters
levelThe level that must be matched
callbackThe funtion to be called
userDataUser date to pass to the callback function
Returns
bool Return true if the callback was registered

◆ setMinLevel()

void Logger::setMinLevel ( const std::string &  level)

Set the minimum level of logging to write to syslog.

Parameters
levelThe minimum, inclusive, level of logging to write

◆ unregisterInterceptor()

bool Logger::unregisterInterceptor ( LogLevel  level,
LogInterceptor  callback 
)

Remove the registration of a previously registered callback.

Parameters
levelThe matching log level for the callback
callbackThe callback to unregister
Returns
bool True if the callback was unregistered.

◆ warn()

void Logger::warn ( const std::string &  msg,
  ... 
)

Log a message at the level warn.

Parameters
msgA printf format string
...The variable arguments required by the printf format

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