Package ucar.unidata.util
Class LogUtil
java.lang.Object
ucar.unidata.util.LogUtil
Class LogUtil
- Author:
- Unidata development team
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
DialogManager is an interface that allows an applcation to add its own buttons to the error dialogsstatic class
Class LogCategory serves as a wrapper around some (undefined for now) logging facility. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Add the given component into the list of components that show messages from the message method callsstatic void
Add the given component into the list of components that show messages from the message method callsstatic boolean
If we are in test mode have there been any errors logged.static void
clearMessage
(String message) If the given message is the same as the last shown message then clear all messagesstatic void
Configure the loggingstatic void
consoleMessage
(String msg) Append the given msg to the console text area.static Window
Finds the most recent active window.static boolean
Set the debug modestatic List
Get the list of exceptions that were thrown when in test modestatic Throwable
Get any exception that the given exception wraps (if it does).static boolean
_more_static LogUtil.LogCategory
getLogInstance
(String name) Helper that creates a log category.static List
Get the list of messages for errors when in test modestatic JPanel
getMultiExceptionsPanel
(List errorMessages, List exceptions) Create the panel that shows multiple exceptionsstatic String
getOutputBuffer
(boolean andClearIt) Get the text that has been written to stderr/stdout when in buffering modestatic boolean
Do we show errors in guistatic StringBuffer
getStackDump
(boolean asHtml) return the stack trace of all threadsstatic StringBuffer
getStackDump
(boolean asHtml, boolean onlyRunning) return the stack trace of all threadsstatic String
Return the stack trace of this calling threadstatic String
getStackTrace
(Throwable exc) Get the stack trace from the given exceptionstatic boolean
Are we in test modestatic void
logException
(String msg, Throwable exc) Log the given error message and exceptionstatic void
Show the given string in all of the message componentsstatic void
printException
(LogUtil.LogCategory log_, String xmsg, Throwable exc) Show the given error message/exception in the gui (if not in test mode), print it to the console and log it to the given Categorystatic void
printException
(LogUtil.LogCategory log_, String xmsg, Throwable exc, byte[] fileBytes) Print the exceptionstatic void
printException
(LogUtil.LogCategory log_, String xmsg, Throwable originalException, File file) Print the exceptionstatic void
printExceptionNoGui
(LogUtil.LogCategory log_, String xmsg, Throwable exc) Log the given error message/exception to the given LogCategorystatic void
printExceptions
(String label, List errorMessages, List exceptions) Print exceptionsstatic void
printExceptions
(List exceptions) Print out the list of exceptionsstatic void
printExceptions
(List errorMessages, List exceptions) Print out the list of error messages and exceptions.static void
printExceptionsNoGui
(String errorMessage, List exceptions) Print out the error messages and exceptions.static void
printExceptionsNoGui
(List errorMessages, List exceptions) print out the list of error messages and exceptions.static void
This allows you to print to stderr even when we are bufferingstatic void
printMessage
(String msg) Simply print the given message using the default logging LogCategory.static void
This registers a window listener on the given window to add and remove the the window to the list of active windows.static void
Remove the given component from the list of message componentsstatic void
static void
setDebugMode
(boolean v) Set the debug modestatic void
setDialogManager
(LogUtil.DialogManager manager) Allows applications to add their own LogUtil.DialogManagerstatic void
setShowErrorsInGui
(boolean v) set if we show the errors in the guistatic void
setTestMode
(boolean v) Set the test mode.static void
Create (if needed) the Console window and show itstatic boolean
showGui()
static void
Start buffering stderr and stdoutstatic void
Stop buffering stderr and stdoutstatic void
Helps to track down println callsstatic void
userErrorMessage
(Object msg) Show the error dialog to the userstatic void
userErrorMessage
(String msg) Show the error dialog to the userstatic void
userErrorMessage
(JLabel label) Show the given label in an error dialog.static void
userErrorMessage
(LogUtil.LogCategory log_, String msg) Show the error dialog to the userstatic void
userMessage
(String msg) Show an informational message to the user.static void
userMessage
(LogUtil.LogCategory log_, String msg) Show an informational message to the user.static void
userMessage
(LogUtil.LogCategory log_, String msg, boolean andLog) Show an informational message to the user.static void
userMessage
(LogUtil.LogCategory log_, String msg, String consoleMsg) Show an informational message to the user.
-
Field Details
-
printlncnt
public static int printlncntHelps to track down println calls
-
-
Method Details
-
getLogInstance
Helper that creates a log category. We have this here so we can always add in some logging facility later.- Parameters:
name
- The name of the log instance- Returns:
- The wrapper around the logger
-
anyErrors
public static boolean anyErrors()If we are in test mode have there been any errors logged.- Returns:
- Any errors logged.
-
getExceptions
Get the list of exceptions that were thrown when in test mode- Returns:
- List of exceptions from test mode
-
getMessages
Get the list of messages for errors when in test mode- Returns:
- List of error messages
-
setTestMode
public static void setTestMode(boolean v) Set the test mode. If true then we don't popup any error or message dialogs. Instead we log the exceptions in a list that is dumped out later by any test running code.- Parameters:
v
- The test mode flag
-
getTestMode
public static boolean getTestMode()Are we in test mode- Returns:
- in test mode
-
showGui
public static boolean showGui() -
setShowErrorsInGui
public static void setShowErrorsInGui(boolean v) set if we show the errors in the gui- Parameters:
v
- The test mode flag
-
getShowErrorsInGui
public static boolean getShowErrorsInGui()Do we show errors in gui- Returns:
- show errors in gui
-
getInteractiveMode
public static boolean getInteractiveMode()_more_- Returns:
- _more_
-
setDebugMode
public static void setDebugMode(boolean v) Set the debug mode- Parameters:
v
- the debug flag (true to print out debug messages)
-
getDebugMode
public static boolean getDebugMode()Set the debug mode- Returns:
- the debug flag (true to print out debug messages)
-
configure
public static void configure()Configure the logging -
logException
Log the given error message and exception- Parameters:
msg
- The error messageexc
- The exception
-
printExceptionsNoGui
print out the list of error messages and exceptions. Do not show them in the gui.- Parameters:
errorMessages
-exceptions
-
-
printExceptionsNoGui
Print out the error messages and exceptions. Do not show them in the gui.- Parameters:
errorMessage
- The messageexceptions
- The exceptions
-
printExceptions
Print out the list of exceptions- Parameters:
exceptions
- The exceptions
-
println
This allows you to print to stderr even when we are buffering- Parameters:
msg
- The text to print
-
startOutputBuffer
public static void startOutputBuffer()Start buffering stderr and stdout -
getOutputBuffer
Get the text that has been written to stderr/stdout when in buffering mode- Parameters:
andClearIt
- Clear the buffer- Returns:
- The buffer
-
stopOutputBuffer
public static void stopOutputBuffer()Stop buffering stderr and stdout -
printExceptions
Print out the list of error messages and exceptions. If not in test mode then show them in a gui. If in test mode then just print to stderr.- Parameters:
errorMessages
- The error messagesexceptions
- The exceptions
-
printExceptions
Print exceptions- Parameters:
label
- label for the dialogerrorMessages
- list of error messagesexceptions
- List of exceptions
-
getInnerException
Get any exception that the given exception wraps (if it does).- Parameters:
exc
- The possible exception containing exception- Returns:
- The wrapped exception or the given exception if it does not wrap one.
-
getMultiExceptionsPanel
Create the panel that shows multiple exceptions- Parameters:
errorMessages
- The error messagesexceptions
- The exceptions- Returns:
- The panel that shows the multiple exceptions
-
getStackTrace
Return the stack trace of this calling thread- Returns:
- The stack trace
-
getStackTrace
Get the stack trace from the given exception- Parameters:
exc
- The exception to get the trace from- Returns:
- The stack trace
-
showConsole
public static void showConsole()Create (if needed) the Console window and show it -
runGemini
-
consoleMessage
Append the given msg to the console text area. This will not show the console. To do that call showConsole.- Parameters:
msg
-
-
setDialogManager
Allows applications to add their own LogUtil.DialogManager- Parameters:
manager
- The singleton dialog manager to use
-
getCurrentWindow
Finds the most recent active window. If there are none then it returns null.- Returns:
- The most recently active window.
-
registerWindow
This registers a window listener on the given window to add and remove the the window to the list of active windows.- Parameters:
w
- The window
-
printException
Show the given error message/exception in the gui (if not in test mode), print it to the console and log it to the given Category- Parameters:
log_
- The LogCatgory to log the error toxmsg
- The error messageexc
- The exception
-
printException
public static void printException(LogUtil.LogCategory log_, String xmsg, Throwable exc, byte[] fileBytes) Print the exception- Parameters:
log_
- log categoryxmsg
- messageexc
- exceptionfileBytes
- if non-null then write to a tmp file and tell the user where to find it.
-
printException
public static void printException(LogUtil.LogCategory log_, String xmsg, Throwable originalException, File file) Print the exception- Parameters:
log_
- log categoryxmsg
- messageoriginalException
- exceptionfile
- If non-null then this is the tmp file that was written Tell the user about it.
-
printExceptionNoGui
Log the given error message/exception to the given LogCategory- Parameters:
log_
- The LogCategory to log the error toxmsg
- The error messageexc
- The exception
-
printMessage
Simply print the given message using the default logging LogCategory. The effect of this is to print the message to the stderr and to the console.- Parameters:
msg
-
-
userMessage
Show an informational message to the user. We have this here so we can control when a dialog is shown (we don't show them when in test mode).- Parameters:
msg
- The message
-
userMessage
Show an informational message to the user. We have this here so we can control when a dialog is shown (we don't show them when in test mode). Also log the message to the given LogCategory (if not null).- Parameters:
log_
- The category to log to. May be null.msg
- The message
-
userMessage
Show an informational message to the user. We have this here so we can control when a dialog is shown (we don't show them when in test mode). Also log the message to the given LogCategory (if not null).- Parameters:
log_
- The category to log to. May be null.msg
- The messageconsoleMsg
- What to show in the error console
-
userMessage
Show an informational message to the user. We have this here so we can control when a dialog is shown (we don't show them when in test mode). Also log the message to the given LogCategory (if not null).- Parameters:
log_
- The category to log to. May be null.msg
- The messageandLog
- Should we also log it to the log_
-
userErrorMessage
Show the error dialog to the user- Parameters:
log_
- category to log to (if not null).msg
- The message
-
userErrorMessage
Show the given label in an error dialog. If for some reason we are in no gui mode then just print out the text of the label- Parameters:
label
- label
-
userErrorMessage
Show the error dialog to the user- Parameters:
msg
- The message
-
userErrorMessage
Show the error dialog to the user- Parameters:
msg
- May be a String or a Component
-
addMessageLogger
Add the given component into the list of components that show messages from the message method calls- Parameters:
t
- The text component
-
addMessageLogger
Add the given component into the list of components that show messages from the message method calls- Parameters:
t
- The text component
-
removeMessageLogger
Remove the given component from the list of message components- Parameters:
t
- The component to remove
-
clearMessage
If the given message is the same as the last shown message then clear all messages- Parameters:
message
- The message to clear
-
message
Show the given string in all of the message components- Parameters:
msg
- The message to show
-
tracePrintlns
public static void tracePrintlns()Helps to track down println calls -
getStackDump
return the stack trace of all threads- Parameters:
asHtml
- If true generate html instead of text- Returns:
- stack dump
-
getStackDump
return the stack trace of all threads- Parameters:
asHtml
- If true generate html instead of textonlyRunning
- Only show the running threads- Returns:
- stack dump
-