Class TrcTraceLogger

java.lang.Object
trclib.robotcore.TrcTraceLogger

public class TrcTraceLogger extends Object
  • Field Details

    • tracer

      public final TrcDbgTrace tracer
    • traceLogName

      private final String traceLogName
    • msgQueue

      private final LinkedBlockingQueue<String> msgQueue
    • traceLog

      private PrintWriter traceLog
    • loggerThread

      private volatile Thread loggerThread
    • enabled

      private volatile boolean enabled
    • totalNanoTime

      private double totalNanoTime
    • totalMessages

      private int totalMessages
  • Constructor Details

    • TrcTraceLogger

      public TrcTraceLogger(String traceLogName)
      Constructor: Create an instance of the trace logger.
      Parameters:
      traceLogName - specifies the log file name.
  • Method Details

    • toString

      public String toString()
      This method returns the trace log name.
      Overrides:
      toString in class Object
      Returns:
      trace log name, "None" if no log file opened.
    • 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

      public boolean logMessage(String msg)
      This method is called to log a message to the log file.
      Parameters:
      msg - specifies the message to be logged.
    • writeMessage

      private void writeMessage(String msg)
      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.