Package trclib.robotcore
Class TrcTraceLogger
java.lang.Object
trclib.robotcore.TrcTraceLogger
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate Threadprivate final LinkedBlockingQueue<String>private intprivate doubleprivate PrintWriterprivate final Stringfinal TrcDbgTrace -
Constructor Summary
ConstructorsConstructorDescriptionTrcTraceLogger(String traceLogName) Constructor: Create an instance of the trace logger. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidThis method closes the trace log file.booleanThis method checks if the trace log is enabled.private voidThis method is called when the logger thread is started.booleanlogMessage(String msg) This method is called to log a message to the log file.voidsetEnabled(boolean enabled) This method enables/disables the trace logger thread.toString()This method returns the trace log name.private voidwriteMessage(String msg) This method writes the message to the trace log and also keeps track of logging performance.
-
Field Details
-
tracer
-
traceLogName
-
msgQueue
-
traceLog
-
loggerThread
-
enabled
private volatile boolean enabled -
totalNanoTime
private double totalNanoTime -
totalMessages
private int totalMessages
-
-
Constructor Details
-
TrcTraceLogger
Constructor: Create an instance of the trace logger.- Parameters:
traceLogName- specifies the log file name.
-
-
Method Details
-
toString
This method returns the trace log name. -
setEnabled
public void setEnabled(boolean enabled) This method enables/disables the trace logger thread.- Parameters:
enabled- specifies true to enable logger thread, false to disable.
-
isEnabled
public boolean isEnabled()This method checks if the trace log is enabled.- Returns:
- true if trace log is enabled, false if disabled.
-
logMessage
This method is called to log a message to the log file.- Parameters:
msg- specifies the message to be logged.
-
writeMessage
This method writes the message to the trace log and also keeps track of logging performance.- Parameters:
msg- specifies the message to be logged.
-
closeTraceLog
private void closeTraceLog()This method closes the trace log file. -
loggerTask
private void loggerTask()This method is called when the logger thread is started. It processes all messages in the message queue when they arrive. If the message queue is empty, the thread is blocked until a new message arrives. Therefore, this thread only runs when there are messages in the queue. If this thread is interrupted, it will exit only after all the remaining messages in the queue are written to the log.
-