Package org.robwork.sdurw_core
Class Log
- java.lang.Object
-
- org.robwork.sdurw_core.Log
-
public class Log extends java.lang.ObjectProvides 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";
or on the log instance
Log &log = Log::log(); 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";
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);
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);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLog.LogIndexIndices for different logs.static classLog.LogIndexMaskloglevel mask
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description LogWriterdebug()convenience function for getting the LogWriter
that is associated with the debug loglevelstatic LogWriterdebugLog()convenience function for getting the LogWriter
that is associated with the debug loglevelvoiddecreaseTabLevel()Decrease the indentation.voiddelete()LogWritererror()convenience function for getting the LogWriter
that is associated with the error loglevelstatic LogWritererrorLog()convenience function for getting the LogWriter
that is associated with the error loglevelvoidflush(Log.LogIndex id)Calls flush on the specified log
If the id cannot be found an exception is thrown
voidflushAll()Calls flush on all logsLogWriterget(Log.LogIndex id)Returns the LogWriter that is associated with LogIndex id
If the id is unknown an exception is thrown.
static longgetCPtr(Log obj)static LogPtrgetInstance()returns the global log instance.intgetLogIndexMask()get the current log maskLogWritergetLogWriter(Log.LogIndex id)Returns the LogWriter that is associated with LogIndex id
If the id is unknown an exception is thrown.
LogWriterPtrgetWriter(Log.LogIndex id)gets the log writer associated to logindex idvoidincreaseTabLevel()Make indentation to make logs easier to read.LogWriterinfo()convenience function for getting the LogWriter
that is associated with the info loglevelstatic LogWriterinfoLog()convenience function for getting the LogWriter
that is associated with the info loglevelbooleanisEnabled(Log.LogIndex idx)Checks if the given LogIndex is enabled.static Loglog()convenience function of getInstancevoidremove(Log.LogIndex id)Removes a log
If the id cannot be found an exception is thrown
voidremoveAll()Removes all log writersvoidsetDisable(int mask)Disable log(s) given by log mask.voidsetEnable(int mask)Enable log(s) given by log mask.voidsetLevel(Log.LogIndex loglevel)set the loglevel.static voidsetLog(LogPtr log)sets the instance of the log classvoidsetLogIndexMask(int mask)the loglevel is a runtime handle for enabling/disabling
logging to specific loglevels.voidsetWriter(Log.LogIndex id, LogWriterPtr 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");
voidsetWriterForMask(int mask, LogWriterPtr 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");
static Log.LogIndexMasktoMask(Log.LogIndex idx)Convert a LogIndex to a mask.LogWriterwarning()convenience function for getting the LogWriter
that is associated with the warning loglevelstatic LogWriterwarningLog()convenience function for getting the LogWriter
that is associated with the warning loglevelvoidwrite(Log.LogIndex id, java.lang.String message)Writes message to the log
If the id cannot be found an exception is thrown
voidwrite(Log.LogIndex id, Message message)Writes message to the logwriter associated with LogIndex id
If the id cannot be found an exception is thrown
voidwriteln(Log.LogIndex id, java.lang.String message)Writes message followed by a '\n' to the log
If the id cannot be found an exception is thrown
-
-
-
Method Detail
-
getCPtr
public static long getCPtr(Log obj)
-
delete
public void delete()
-
toMask
public static Log.LogIndexMask toMask(Log.LogIndex idx)
Convert a LogIndex to a mask.- Parameters:
idx- [in] the LogIndex.- Returns:
- the mask enabling the given log level.
-
infoLog
public static LogWriter infoLog()
convenience function for getting the LogWriter
that is associated with the info loglevel- Returns:
- info LogWriter
-
warningLog
public static LogWriter warningLog()
convenience function for getting the LogWriter
that is associated with the warning loglevel- Returns:
- warning LogWriter
-
errorLog
public static LogWriter errorLog()
convenience function for getting the LogWriter
that is associated with the error loglevel- Returns:
- error LogWriter
-
debugLog
public static LogWriter debugLog()
convenience function for getting the LogWriter
that is associated with the debug loglevel- Returns:
- debug LogWriter
-
getInstance
public static LogPtr getInstance()
returns the global log instance. Global in the sence
of whatever is linked staticly together.- Returns:
- a Log
-
log
public static Log log()
convenience function of getInstance- Returns:
- a Log
-
setLog
public static void setLog(LogPtr log)
sets the instance of the log class- Parameters:
log- [in] the log that will be used through the static log methods.
-
setLevel
public void setLevel(Log.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- Parameters:
loglevel- [in] the level
-
getWriter
public LogWriterPtr getWriter(Log.LogIndex id)
gets the log writer associated to logindex id- Parameters:
id- [in] logindex- Returns:
- log writer
-
setWriter
public void setWriter(Log.LogIndex id, LogWriterPtr 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");
- Parameters:
id- [in] the LogIndex that the logwriter is associated with.writer- [in] LogWriter object to use
-
setWriterForMask
public void setWriterForMask(int mask, LogWriterPtr 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");
- Parameters:
mask- [in] the LogIndexMask that the logwriter is associated with.writer- [in] LogWriter object to use
-
get
public LogWriter get(Log.LogIndex id)
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
-
write
public void write(Log.LogIndex id, java.lang.String message)
Writes message to the log
If the id cannot be found an exception is thrown
- Parameters:
id- [in] Log identifiermessage- [in] String message to write
-
write
public void write(Log.LogIndex id, 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 identifiermessage- [in] Message to write
-
writeln
public void writeln(Log.LogIndex id, java.lang.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 identifiermessage- [in] Message to write
-
flush
public void flush(Log.LogIndex id)
Calls flush on the specified log
If the id cannot be found an exception is thrown
- Parameters:
id- [in] loglevel
-
flushAll
public void flushAll()
Calls flush on all logs
-
remove
public void remove(Log.LogIndex id)
Removes a log
If the id cannot be found an exception is thrown
- Parameters:
id- [in] Log identifier
-
removeAll
public void removeAll()
Removes all log writers
-
increaseTabLevel
public void increaseTabLevel()
Make indentation to make logs easier to read.
-
decreaseTabLevel
public void decreaseTabLevel()
Decrease the indentation.
-
info
public LogWriter info()
convenience function for getting the LogWriter
that is associated with the info loglevel- Returns:
- info LogWriter
-
warning
public LogWriter warning()
convenience function for getting the LogWriter
that is associated with the warning loglevel- Returns:
- info LogWriter
-
error
public LogWriter error()
convenience function for getting the LogWriter
that is associated with the error loglevel- Returns:
- info LogWriter
-
debug
public LogWriter debug()
convenience function for getting the LogWriter
that is associated with the debug loglevel- Returns:
- info LogWriter
-
setLogIndexMask
public void setLogIndexMask(int mask)
the loglevel is a runtime handle for enabling/disabling
logging to specific loglevels.- Parameters:
mask-
Note: DEPRECATED. Use setEnable/setDisable instead
-
getLogIndexMask
public int getLogIndexMask()
get the current log mask- Returns:
- the LogIndex
Note: DEPRECATED. To be removed
-
setEnable
public void setEnable(int mask)
Enable log(s) given by log mask.- Parameters:
mask- [in] the mask for the logs to enable.
-
isEnabled
public boolean isEnabled(Log.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.- Parameters:
idx- [in] the level
-
setDisable
public void setDisable(int mask)
Disable log(s) given by log mask.- Parameters:
mask- [in] the mask for the logs to disable.
-
getLogWriter
public LogWriter getLogWriter(Log.LogIndex id)
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
-
-