Class Logger

java.lang.Object
cz.fidentis.analyst.Logger

public final class Logger extends Object
A logging class that can be used from anywhere to display debugging or other messages.

Messages are printed into the system standard output by default. But can be also redirected to system error output or into the pipe.

If the messages are redirected into pipe, then a consumer has to be running concurrently and reading the data through the read() method. Otherwise, the program can freeze due to the full buffer!

FIDENTIS application automatically redirects logged messages to the output window via the OutputWindowThread.

Usage:

  • To print a message, use Logger.print("message"). A timestamp is added automatically.
  • To print message together with duration, call Logger log = Logger.measureTime();, then call the measured operations and finally call log.printDuration("message"). a timestamp and measured duration are added to the log message automatically.
  • Method Details

    • redirectToPipe

      public static void redirectToPipe()
      Redirects messages into a pipe. A consumer has to be running concurrently and reading the messages through the read() method. Otherwise, the program can freeze due to the full buffer!
    • redirectToStdOut

      public static void redirectToStdOut()
      Redirects messages into the system standard output.
    • redirectToStdErr

      public static void redirectToStdErr()
      Redirects messages into the system error output.
    • read

      public static String read() throws IOException
      Returns an event message. If the logger is redirected to standard or error output, then null is returned. Also, if the is no message, null is returned.
      Returns:
      Event message or null
      Throws:
      IOException - on error in reading the message buffer.
    • print

      public static void print(String msg)
      Prints a message. The log time added automatically.
      Parameters:
      msg - Message to be logged
    • measureTime

      public static Logger measureTime()
      Starts measuring of some operation. Call printDuration(java.lang.String) on returned object to print the measured duration.
      Returns:
      An object used to print measured duration and message
    • printDuration

      public void printDuration(String msg)
      Prints the message about an operation and the duration of the operation. The duration is computed as the difference between current system time and the time of calling measureTime(). The time difference is measured in milliseconds and printed as [+mm:ss.SSS] where mm=minutes, ss=seconds, and SSS=milliseconds.
      Parameters:
      msg - Message to be printed