Class LogUtil

java.lang.Object
ucar.unidata.util.LogUtil

public class LogUtil extends Object
Class LogUtil
Author:
Unidata development team
  • Field Details

    • printlncnt

      public static int printlncnt
      Helps to track down println calls
  • Method Details

    • getLogInstance

      public static LogUtil.LogCategory getLogInstance(String name)
      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

      public static List getExceptions()
      Get the list of exceptions that were thrown when in test mode
      Returns:
      List of exceptions from test mode
    • getMessages

      public static List 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

      public static void logException(String msg, Throwable exc)
      Log the given error message and exception
      Parameters:
      msg - The error message
      exc - The exception
    • printExceptionsNoGui

      public static void printExceptionsNoGui(List errorMessages, List exceptions)
      print out the list of error messages and exceptions. Do not show them in the gui.
      Parameters:
      errorMessages -
      exceptions -
    • printExceptionsNoGui

      public static void printExceptionsNoGui(String errorMessage, List exceptions)
      Print out the error messages and exceptions. Do not show them in the gui.
      Parameters:
      errorMessage - The message
      exceptions - The exceptions
    • printExceptions

      public static void printExceptions(List exceptions)
      Print out the list of exceptions
      Parameters:
      exceptions - The exceptions
    • println

      public static void println(String msg)
      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

      public static String getOutputBuffer(boolean andClearIt)
      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

      public static void printExceptions(List errorMessages, List exceptions)
      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 messages
      exceptions - The exceptions
    • printExceptions

      public static void printExceptions(String label, List errorMessages, List exceptions)
      Print exceptions
      Parameters:
      label - label for the dialog
      errorMessages - list of error messages
      exceptions - List of exceptions
    • getInnerException

      public static Throwable getInnerException(Throwable exc)
      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

      public static JPanel getMultiExceptionsPanel(List errorMessages, List exceptions)
      Create the panel that shows multiple exceptions
      Parameters:
      errorMessages - The error messages
      exceptions - The exceptions
      Returns:
      The panel that shows the multiple exceptions
    • getStackTrace

      public static String getStackTrace()
      Return the stack trace of this calling thread
      Returns:
      The stack trace
    • getStackTrace

      public static String getStackTrace(Throwable exc)
      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

      public static void runGemini(String imagePath)
    • consoleMessage

      public static void consoleMessage(String msg)
      Append the given msg to the console text area. This will not show the console. To do that call showConsole.
      Parameters:
      msg -
    • setDialogManager

      public static void setDialogManager(LogUtil.DialogManager manager)
      Allows applications to add their own LogUtil.DialogManager
      Parameters:
      manager - The singleton dialog manager to use
    • getCurrentWindow

      public static Window getCurrentWindow()
      Finds the most recent active window. If there are none then it returns null.
      Returns:
      The most recently active window.
    • registerWindow

      public static void registerWindow(Window w)
      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

      public static 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 Category
      Parameters:
      log_ - The LogCatgory to log the error to
      xmsg - The error message
      exc - The exception
    • printException

      public static void printException(LogUtil.LogCategory log_, String xmsg, Throwable exc, byte[] fileBytes)
      Print the exception
      Parameters:
      log_ - log category
      xmsg - message
      exc - exception
      fileBytes - 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 category
      xmsg - message
      originalException - exception
      file - If non-null then this is the tmp file that was written Tell the user about it.
    • printExceptionNoGui

      public static void printExceptionNoGui(LogUtil.LogCategory log_, String xmsg, Throwable exc)
      Log the given error message/exception to the given LogCategory
      Parameters:
      log_ - The LogCategory to log the error to
      xmsg - The error message
      exc - The exception
    • printMessage

      public static void printMessage(String msg)
      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

      public static void userMessage(String msg)
      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

      public static void userMessage(LogUtil.LogCategory log_, String msg)
      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

      public static void userMessage(LogUtil.LogCategory log_, String msg, String consoleMsg)
      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
      consoleMsg - What to show in the error console
    • userMessage

      public static void userMessage(LogUtil.LogCategory log_, String msg, boolean andLog)
      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
      andLog - Should we also log it to the log_
    • userErrorMessage

      public static void userErrorMessage(LogUtil.LogCategory log_, String msg)
      Show the error dialog to the user
      Parameters:
      log_ - category to log to (if not null).
      msg - The message
    • userErrorMessage

      public static void userErrorMessage(JLabel label)
      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

      public static void userErrorMessage(String msg)
      Show the error dialog to the user
      Parameters:
      msg - The message
    • userErrorMessage

      public static void userErrorMessage(Object msg)
      Show the error dialog to the user
      Parameters:
      msg - May be a String or a Component
    • addMessageLogger

      public static void addMessageLogger(JTextArea t)
      Add the given component into the list of components that show messages from the message method calls
      Parameters:
      t - The text component
    • addMessageLogger

      public static void addMessageLogger(JLabel t)
      Add the given component into the list of components that show messages from the message method calls
      Parameters:
      t - The text component
    • removeMessageLogger

      public static void removeMessageLogger(Object t)
      Remove the given component from the list of message components
      Parameters:
      t - The component to remove
    • clearMessage

      public static void clearMessage(String message)
      If the given message is the same as the last shown message then clear all messages
      Parameters:
      message - The message to clear
    • message

      public static void message(String msg)
      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

      public static StringBuffer getStackDump(boolean asHtml)
      return the stack trace of all threads
      Parameters:
      asHtml - If true generate html instead of text
      Returns:
      stack dump
    • getStackDump

      public static StringBuffer getStackDump(boolean asHtml, boolean onlyRunning)
      return the stack trace of all threads
      Parameters:
      asHtml - If true generate html instead of text
      onlyRunning - Only show the running threads
      Returns:
      stack dump