RobWorkProject  23.9.11-
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Log Class Reference

Provides basic log functionality. More...

#include <Log.hpp>

Public Types

enum  LogIndexMask {
  FatalMask = 1 , CriticalMask = 2 , ErrorMask = 4 , WarningMask = 8 ,
  InfoMask = 16 , DebugMask = 32 , User1Mask = 64 , User2Mask = 128 ,
  User3Mask = 256 , User4Mask = 512 , User5Mask = 1024 , User6Mask = 2048 ,
  User7Mask = 4096 , User8Mask = 8096 , AllMask = 0xFFFF
}
 loglevel mask
 
enum  LogIndex {
  Fatal = 0 , Critical = 1 , Error = 2 , Warning = 3 ,
  Info = 4 , Debug = 5 , User1 = 6 , User2 = 7 ,
  User3 = 8 , User4 = 9 , User5 = 10 , User6 = 11 ,
  User7 = 12 , User8 = 13
}
 Indices for different logs. The loglevel will be Info as default. Everything below the loglevel is enabled.
 
typedef rw::core::Ptr< LogPtr
 smart pointer type to this class
 

Public Member Functions

 Log ()
 constructor
 
virtual ~Log ()
 Destructor.
 
void setLevel (LogIndex loglevel)
 set the loglevel. Any log with LogIndex equal to or less than loglevel will be enabled. Any log above will be disabled unless an enabled mask is specified for that log More...
 
rw::core::LogWriter::Ptr getWriter (LogIndex id)
 gets the log writer associated to logindex id More...
 
void setWriter (LogIndex id, rw::core::LogWriter::Ptr writer)
 Associates a LogWriter with the LogIndex id. More...
 
void setWriterForMask (int mask, rw::core::LogWriter::Ptr writer)
 Associates a LogWriter with the logs specified with mask. More...
 
rw::core::LogWriterget (LogIndex id)
 Returns the LogWriter that is associated with LogIndex id. More...
 
void write (LogIndex id, const std::string &message)
 Writes message to the log. More...
 
void write (LogIndex id, const rw::core::Message &message)
 Writes message to the logwriter associated with LogIndex id. More...
 
void writeln (LogIndex id, const std::string &message)
 Writes message followed by a '\n' to the log. More...
 
void flush (LogIndex id)
 Calls flush on the specified log. More...
 
void flushAll ()
 Calls flush on all logs.
 
void remove (LogIndex id)
 Removes a log. More...
 
void removeAll ()
 Removes all log writers.
 
void increaseTabLevel ()
 Make indentation to make logs easier to read.
 
void decreaseTabLevel ()
 Decrease the indentation.
 
rw::core::LogWriterinfo ()
 convenience function for getting the LogWriter that is associated with the info loglevel More...
 
rw::core::LogWriterwarning ()
 convenience function for getting the LogWriter that is associated with the warning loglevel More...
 
rw::core::LogWritererror ()
 convenience function for getting the LogWriter that is associated with the error loglevel More...
 
rw::core::LogWriterdebug ()
 convenience function for getting the LogWriter that is associated with the debug loglevel More...
 
void setLogIndexMask (int mask)
 the loglevel is a runtime handle for enabling/disabling logging to specific loglevels. More...
 
int getLogIndexMask () const
 get the current log mask More...
 
void setEnable (int mask)
 Enable log(s) given by log mask. More...
 
bool isEnabled (LogIndex idx)
 Checks if the given LogIndex is enabled. This can be used to determine if a certain log level will be displayed or not. More...
 
void setDisable (int mask)
 Disable log(s) given by log mask. More...
 

Static Public Member Functions

static LogIndexMask toMask (LogIndex idx)
 Convert a LogIndex to a mask. More...
 
static rw::core::LogWriterinfoLog ()
 convenience function for getting the LogWriter that is associated with the info loglevel More...
 
static rw::core::LogWriterwarningLog ()
 convenience function for getting the LogWriter that is associated with the warning loglevel More...
 
static rw::core::LogWritererrorLog ()
 convenience function for getting the LogWriter that is associated with the error loglevel More...
 
static rw::core::LogWriterdebugLog ()
 convenience function for getting the LogWriter that is associated with the debug loglevel More...
 
static Log::Ptr getInstance ()
 returns the global log instance. Global in the sence of whatever is linked staticly together. More...
 
static Loglog ()
 convenience function of getInstance More...
 
static void setLog (Log::Ptr log)
 sets the instance of the log class More...
 

Detailed Description

Provides basic log functionality.

The Log class owns a number of LogWriters in a static map, which can be accessed using a string identifier. All logs are global.

By default the Log class contains a Debug, Info, Warning and Error log. These can be accessed statically as:

Log::debugLog() << "This is an debug message";
Log::infoLog() << "This is an info message";
Log::warnLog() << "This is an error message";
Log::errorLog() << "This is an error message";
static rw::core::LogWriter & errorLog()
convenience function for getting the LogWriter that is associated with the error loglevel
Definition: core/Log.hpp:169
static rw::core::LogWriter & debugLog()
convenience function for getting the LogWriter that is associated with the debug loglevel
Definition: core/Log.hpp:176
static rw::core::LogWriter & infoLog()
convenience function for getting the LogWriter that is associated with the info loglevel
Definition: core/Log.hpp:155

or on the log instance

log.debug() << "This is an debug message";
log.info() << "This is an info message";
log.warn() << "This is an error message";
log.error() << "This is an error message";
rw::core::LogWriter & error()
convenience function for getting the LogWriter that is associated with the error loglevel
Definition: core/Log.hpp:358
static Log & log()
convenience function of getInstance
Log()
constructor
rw::core::LogWriter & info()
convenience function for getting the LogWriter that is associated with the info loglevel
Definition: core/Log.hpp:338
rw::core::LogWriter & debug()
convenience function for getting the LogWriter that is associated with the debug loglevel
Definition: core/Log.hpp:368

or using one one the RW_LOG, RW_LOGLINE or RW_LOG2 macros, e.g.

RW_LOG_INFO("The value of x is "<<x);
RW_LOG_DEBUG("The value of x is "<<x);
RW_LOG_ERROR(Log::infoId(), "The value of x is "<<x);
#define RW_LOG_DEBUG(ostreamExpression)
Writes ostreamExpression to debug log.
Definition: core/macros.hpp:212
#define RW_LOG_INFO(ostreamExpression)
Writes ostreamExpression to info log.
Definition: core/macros.hpp:218
#define RW_LOG_ERROR(ostreamExpression)
Writes ostreamExpression to error log.
Definition: core/macros.hpp:200

You can control what logs are active both using a loglevel and by using a log mask. The loglevel enables all logs with LogIndex lower or equal to the loglevel. As default loglevel is LogIndex::info which means debug and all user logs are disabled. However, logs can be individually enabled using log masks which will override loglevel setting.

Notice that logmasks cannot disable logs that are below or equal to loglevel.

change loglevel:

Log::log().setLevel(Log::Debug);
void setLevel(LogIndex loglevel)
set the loglevel. Any log with LogIndex equal to or less than loglevel will be enabled....
Definition: core/Log.hpp:215

Member Function Documentation

◆ debug()

rw::core::LogWriter& debug ( )
inline

convenience function for getting the LogWriter that is associated with the debug loglevel

Returns
info LogWriter

◆ debugLog()

static rw::core::LogWriter& debugLog ( )
inlinestatic

convenience function for getting the LogWriter that is associated with the debug loglevel

Returns
debug LogWriter

◆ error()

rw::core::LogWriter& error ( )
inline

convenience function for getting the LogWriter that is associated with the error loglevel

Returns
info LogWriter

◆ errorLog()

static rw::core::LogWriter& errorLog ( )
inlinestatic

convenience function for getting the LogWriter that is associated with the error loglevel

Returns
error LogWriter

◆ flush()

void flush ( LogIndex  id)

Calls flush on the specified log.

If the id cannot be found an exception is thrown

Parameters
id[in] loglevel

◆ get()

Returns the LogWriter that is associated with LogIndex id.

If the id is unknown an exception is thrown.

Parameters
id[in] loglevel
Returns
Reference to LogWriter object

◆ getInstance()

static Log::Ptr getInstance ( )
static

returns the global log instance. Global in the sence of whatever is linked staticly together.

Returns
a Log

◆ getLogIndexMask()

int getLogIndexMask ( ) const
inline

get the current log mask

Returns
the LogIndex
Note
DEPRECATED. To be removed

◆ getWriter()

gets the log writer associated to logindex id

Parameters
id[in] logindex
Returns
log writer

◆ info()

rw::core::LogWriter& info ( )
inline

convenience function for getting the LogWriter that is associated with the info loglevel

Returns
info LogWriter

◆ infoLog()

static rw::core::LogWriter& infoLog ( )
inlinestatic

convenience function for getting the LogWriter that is associated with the info loglevel

Returns
info LogWriter

◆ isEnabled()

bool isEnabled ( LogIndex  idx)
inline

Checks if the given LogIndex is enabled. This can be used to determine if a certain log level will be displayed or not.

Parameters
idx[in] the level

◆ log()

static Log& log ( )
static

convenience function of getInstance

Returns
a Log

◆ remove()

void remove ( LogIndex  id)

Removes a log.

If the id cannot be found an exception is thrown

Parameters
id[in] Log identifier

◆ setDisable()

void setDisable ( int  mask)
inline

Disable log(s) given by log mask.

Parameters
mask[in] the mask for the logs to disable.

◆ setEnable()

void setEnable ( int  mask)
inline

Enable log(s) given by log mask.

Parameters
mask[in] the mask for the logs to enable.

◆ setLevel()

void setLevel ( LogIndex  loglevel)
inline

set the loglevel. Any log with LogIndex equal to or less than loglevel will be enabled. Any log above will be disabled unless an enabled mask is specified for that log

Parameters
loglevel[in] the level

◆ setLog()

static void setLog ( Log::Ptr  log)
static

sets the instance of the log class

Parameters
log[in] the log that will be used through the static log methods.

◆ setLogIndexMask()

void setLogIndexMask ( int  mask)
inline

the loglevel is a runtime handle for enabling/disabling logging to specific loglevels.

Parameters
mask
Note
DEPRECATED. Use setEnable/setDisable instead

◆ setWriter()

void setWriter ( LogIndex  id,
rw::core::LogWriter::Ptr  writer 
)

Associates a LogWriter with the LogIndex id.

SetWriter can either be used to redefine an existing log or to create a new custom output.

Example:

Log::SetWriter(Log::User1, new LogStreamWriter(std::cout));
RW_LOG(Log::User1, "Message send to User log 1");
#define RW_LOG(id, ostreamExpression)
Writes ostreamExpression to log with LogIndex id.
Definition: core/macros.hpp:193
Parameters
id[in] the LogIndex that the logwriter is associated with.
writer[in] LogWriter object to use

◆ setWriterForMask()

void setWriterForMask ( int  mask,
rw::core::LogWriter::Ptr  writer 
)

Associates a LogWriter with the logs specified with mask.

SetWriter can either be used to redefine an existing log or to create a new custom output.

Example:

log.setWriterForMask(Log::InfoMask | Log::DebugMask, new LogStreamWriter(std::cout));
RW_LOG(Log::Info, "Message send to User log 1");
void setWriterForMask(int mask, rw::core::LogWriter::Ptr writer)
Associates a LogWriter with the logs specified with mask.
Parameters
mask[in] the LogIndexMask that the logwriter is associated with.
writer[in] LogWriter object to use

◆ toMask()

static LogIndexMask toMask ( LogIndex  idx)
inlinestatic

Convert a LogIndex to a mask.

Parameters
idx[in] the LogIndex.
Returns
the mask enabling the given log level.

◆ warning()

rw::core::LogWriter& warning ( )
inline

convenience function for getting the LogWriter that is associated with the warning loglevel

Returns
info LogWriter

◆ warningLog()

static rw::core::LogWriter& warningLog ( )
inlinestatic

convenience function for getting the LogWriter that is associated with the warning loglevel

Returns
warning LogWriter

◆ write() [1/2]

void write ( LogIndex  id,
const rw::core::Message message 
)

Writes message to the logwriter associated with LogIndex id.

If the id cannot be found an exception is thrown

Parameters
id[in] Log identifier
message[in] Message to write

◆ write() [2/2]

void write ( LogIndex  id,
const std::string &  message 
)

Writes message to the log.

If the id cannot be found an exception is thrown

Parameters
id[in] Log identifier
message[in] String message to write

◆ writeln()

void writeln ( LogIndex  id,
const std::string &  message 
)

Writes message followed by a '\n' to the log.

If the id cannot be found an exception is thrown

Parameters
id[in] Log identifier
message[in] Message to write

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