Package cz.fidentis.analyst
Class Logger
java.lang.Object
cz.fidentis.analyst.Logger
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 calllog.printDuration("message")
. a timestamp and measured duration are added to the log message automatically.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Logger
Starts measuring of some operation.static void
Prints a message.void
printDuration
(String msg) Prints the message about an operation and the duration of the operation.static String
read()
Returns an event message.static void
Redirects messages into a pipe.static void
Redirects messages into the system error output.static void
Redirects messages into the system standard output.
-
Method Details
-
redirectToPipe
public static void redirectToPipe()Redirects messages into a pipe. A consumer has to be running concurrently and reading the messages through theread()
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
Returns an event message. If the logger is redirected to standard or error output, thennull
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
Prints a message. The log time added automatically.- Parameters:
msg
- Message to be logged
-
measureTime
Starts measuring of some operation. CallprintDuration(java.lang.String)
on returned object to print the measured duration.- Returns:
- An object used to print measured duration and message
-
printDuration
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 callingmeasureTime()
. 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
-