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 interfaceDialogManager is an interface that allows an applcation to add its own buttons to the error dialogsstatic classClass LogCategory serves as a wrapper around some (undefined for now) logging facility. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdd the given component into the list of components that show messages from the message method callsstatic voidAdd the given component into the list of components that show messages from the message method callsstatic booleanIf we are in test mode have there been any errors logged.static voidclearMessage(String message) If the given message is the same as the last shown message then clear all messagesstatic voidConfigure the loggingstatic voidconsoleMessage(String msg) Append the given msg to the console text area.static WindowFinds the most recent active window.static booleanSet the debug modestatic ListGet the list of exceptions that were thrown when in test modestatic ThrowableGet any exception that the given exception wraps (if it does).static boolean_more_static LogUtil.LogCategorygetLogInstance(String name) Helper that creates a log category.static ListGet the list of messages for errors when in test modestatic JPanelgetMultiExceptionsPanel(List errorMessages, List exceptions) Create the panel that shows multiple exceptionsstatic StringgetOutputBuffer(boolean andClearIt) Get the text that has been written to stderr/stdout when in buffering modestatic booleanDo we show errors in guistatic StringBuffergetStackDump(boolean asHtml) return the stack trace of all threadsstatic StringBuffergetStackDump(boolean asHtml, boolean onlyRunning) return the stack trace of all threadsstatic StringReturn the stack trace of this calling threadstatic StringgetStackTrace(Throwable exc) Get the stack trace from the given exceptionstatic booleanAre we in test modestatic voidlogException(String msg, Throwable exc) Log the given error message and exceptionstatic voidShow the given string in all of the message componentsstatic voidprintException(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 voidprintException(LogUtil.LogCategory log_, String xmsg, Throwable exc, byte[] fileBytes) Print the exceptionstatic voidprintException(LogUtil.LogCategory log_, String xmsg, Throwable originalException, File file) Print the exceptionstatic voidprintExceptionNoGui(LogUtil.LogCategory log_, String xmsg, Throwable exc) Log the given error message/exception to the given LogCategorystatic voidprintExceptions(String label, List errorMessages, List exceptions) Print exceptionsstatic voidprintExceptions(List exceptions) Print out the list of exceptionsstatic voidprintExceptions(List errorMessages, List exceptions) Print out the list of error messages and exceptions.static voidprintExceptionsNoGui(String errorMessage, List exceptions) Print out the error messages and exceptions.static voidprintExceptionsNoGui(List errorMessages, List exceptions) print out the list of error messages and exceptions.static voidThis allows you to print to stderr even when we are bufferingstatic voidprintMessage(String msg) Simply print the given message using the default logging LogCategory.static voidThis registers a window listener on the given window to add and remove the the window to the list of active windows.static voidRemove the given component from the list of message componentsstatic voidstatic voidsetDebugMode(boolean v) Set the debug modestatic voidsetDialogManager(LogUtil.DialogManager manager) Allows applications to add their own LogUtil.DialogManagerstatic voidsetShowErrorsInGui(boolean v) set if we show the errors in the guistatic voidsetTestMode(boolean v) Set the test mode.static voidCreate (if needed) the Console window and show itstatic booleanshowGui()static voidStart buffering stderr and stdoutstatic voidStop buffering stderr and stdoutstatic voidHelps to track down println callsstatic voiduserErrorMessage(Object msg) Show the error dialog to the userstatic voiduserErrorMessage(String msg) Show the error dialog to the userstatic voiduserErrorMessage(JLabel label) Show the given label in an error dialog.static voiduserErrorMessage(LogUtil.LogCategory log_, String msg) Show the error dialog to the userstatic voiduserMessage(String msg) Show an informational message to the user.static voiduserMessage(LogUtil.LogCategory log_, String msg) Show an informational message to the user.static voiduserMessage(LogUtil.LogCategory log_, String msg, boolean andLog) Show an informational message to the user.static voiduserMessage(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
-