RobWorkProject
23.9.11-
|
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< Log > | Ptr |
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::LogWriter & | get (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::LogWriter & | info () |
convenience function for getting the LogWriter that is associated with the info loglevel More... | |
rw::core::LogWriter & | warning () |
convenience function for getting the LogWriter that is associated with the warning loglevel More... | |
rw::core::LogWriter & | error () |
convenience function for getting the LogWriter that is associated with the error loglevel More... | |
rw::core::LogWriter & | debug () |
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::LogWriter & | infoLog () |
convenience function for getting the LogWriter that is associated with the info loglevel More... | |
static rw::core::LogWriter & | warningLog () |
convenience function for getting the LogWriter that is associated with the warning loglevel More... | |
static rw::core::LogWriter & | errorLog () |
convenience function for getting the LogWriter that is associated with the error loglevel More... | |
static rw::core::LogWriter & | debugLog () |
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 Log & | log () |
convenience function of getInstance More... | |
static void | setLog (Log::Ptr log) |
sets the instance of the log class More... | |
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:
or on the log instance
or using one one the RW_LOG, RW_LOGLINE or RW_LOG2 macros, e.g.
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:
|
inline |
|
inlinestatic |
|
inline |
|
inlinestatic |
void flush | ( | LogIndex | id | ) |
Calls flush on the specified log.
If the id cannot be found an exception is thrown
id | [in] loglevel |
rw::core::LogWriter& get | ( | LogIndex | id | ) |
|
static |
returns the global log instance. Global in the sence of whatever is linked staticly together.
|
inline |
get the current log mask
rw::core::LogWriter::Ptr getWriter | ( | LogIndex | id | ) |
gets the log writer associated to logindex id
id | [in] logindex |
|
inline |
|
inlinestatic |
|
inline |
Checks if the given LogIndex is enabled. This can be used to determine if a certain log level will be displayed or not.
idx | [in] the level |
void remove | ( | LogIndex | id | ) |
|
inline |
Disable log(s) given by log mask.
mask | [in] the mask for the logs to disable. |
|
inline |
Enable log(s) given by log mask.
mask | [in] the mask for the logs to enable. |
|
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
loglevel | [in] the level |
|
static |
sets the instance of the log class
log | [in] the log that will be used through the static log methods. |
|
inline |
the loglevel is a runtime handle for enabling/disabling logging to specific loglevels.
mask |
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:
id | [in] the LogIndex that the logwriter is associated with. |
writer | [in] LogWriter object to use |
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:
mask | [in] the LogIndexMask that the logwriter is associated with. |
writer | [in] LogWriter object to use |
|
inlinestatic |
Convert a LogIndex to a mask.
idx | [in] the LogIndex. |
|
inline |
|
inlinestatic |
void write | ( | LogIndex | id, |
const rw::core::Message & | message | ||
) |
void write | ( | LogIndex | id, |
const std::string & | message | ||
) |
Writes message to the log.
If the id cannot be found an exception is thrown
id | [in] Log identifier |
message | [in] String message to write |
void writeln | ( | LogIndex | id, |
const std::string & | message | ||
) |