Class Logging

java.lang.Object
org.openstreetmap.josm.tools.Logging

public final class Logging extends Object
This class contains utility methods to log errors and warnings.

There are multiple log levels supported.

Since:
10899
  • Field Details

    • LEVEL_ERROR

      public static final Level LEVEL_ERROR
      The josm internal log level indicating a severe error in the application that usually leads to a crash.
    • LEVEL_WARN

      public static final Level LEVEL_WARN
      The josm internal log level to use when something that may lead to a crash or wrong behaviour has happened.
    • LEVEL_INFO

      public static final Level LEVEL_INFO
      The josm internal log level to use for important events that will be useful when debugging problems
    • LEVEL_DEBUG

      public static final Level LEVEL_DEBUG
      The josm internal log level to print debug output
    • LEVEL_TRACE

      public static final Level LEVEL_TRACE
      The finest log level josm supports. This lets josm print a lot of debug output.
    • LOGGER

      private static final Logger LOGGER
    • WARNINGS

    • startup

      private static final Stopwatch startup
  • Constructor Details

  • Method Details

    • setLogLevel

      public static void setLogLevel(Level level)
      Set the global log level.
      Parameters:
      level - The log level to use
    • error

      public static void error(String message)
      Prints an error message if logging is on.
      Parameters:
      message - The message to print.
    • error

      public static void error(String pattern, Object... args)
      Prints a formatted error message if logging is on. Calls MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition) function to format text.
      Parameters:
      pattern - The formatted message to print.
      args - The objects to insert into format string.
    • error

      public static void error(Throwable t)
      Prints an error message for the given Throwable if logging is on.
      Parameters:
      t - The throwable object causing the error.
      Since:
      12620
    • warn

      public static void warn(String message)
      Prints a warning message if logging is on.
      Parameters:
      message - The message to print.
    • warn

      public static void warn(String pattern, Object... args)
      Prints a formatted warning message if logging is on. Calls MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition) function to format text.
      Parameters:
      pattern - The formatted message to print.
      args - The objects to insert into format string.
    • warn

      public static void warn(Throwable t)
      Prints a warning message for the given Throwable if logging is on.
      Parameters:
      t - The throwable object causing the error.
      Since:
      12620
    • info

      public static void info(String message)
      Prints a info message if logging is on.
      Parameters:
      message - The message to print.
    • info

      public static void info(String pattern, Object... args)
      Prints a formatted info message if logging is on. Calls MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition) function to format text.
      Parameters:
      pattern - The formatted message to print.
      args - The objects to insert into format string.
    • info

      public static void info(Throwable t)
      Prints a info message for the given Throwable if logging is on.
      Parameters:
      t - The throwable object causing the error.
      Since:
      12620
    • debug

      public static void debug(String message)
      Prints a debug message if logging is on.
      Parameters:
      message - The message to print.
    • debug

      public static void debug(String pattern, Object... args)
      Prints a formatted debug message if logging is on. Calls MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition) function to format text.
      Parameters:
      pattern - The formatted message to print.
      args - The objects to insert into format string.
    • debug

      public static void debug(Throwable t)
      Prints a debug message for the given Throwable if logging is on.
      Parameters:
      t - The throwable object causing the error.
      Since:
      12620
    • trace

      public static void trace(String message)
      Prints a trace message if logging is on.
      Parameters:
      message - The message to print.
    • trace

      public static void trace(String pattern, Object... args)
      Prints a formatted trace message if logging is on. Calls MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition) function to format text.
      Parameters:
      pattern - The formatted message to print.
      args - The objects to insert into format string.
    • trace

      public static void trace(Throwable t)
      Prints a trace message for the given Throwable if logging is on.
      Parameters:
      t - The throwable object causing the error.
      Since:
      12620
    • log

      public static void log(Level level, Throwable t)
      Logs a throwable that happened. The stack trace is not added to the log.
      Parameters:
      level - The level.
      t - The throwable that should be logged.
      See Also:
    • log

      public static void log(Level level, String message, Throwable t)
      Logs a throwable that happened. The stack trace is not added to the log.
      Parameters:
      level - The level.
      message - An additional error message
      t - The throwable that caused the message
      See Also:
    • logWithStackTrace

      public static void logWithStackTrace(Level level, Throwable t)
      Logs a throwable that happened. Adds the stack trace to the log.
      Parameters:
      level - The level.
      t - The throwable that should be logged.
      See Also:
    • logWithStackTrace

      public static void logWithStackTrace(Level level, String message, Throwable t)
      Logs a throwable that happened. Adds the stack trace to the log.
      Parameters:
      level - The level.
      message - An additional error message
      t - The throwable that should be logged.
      See Also:
    • logWithStackTrace

      public static void logWithStackTrace(Level level, Throwable t, String pattern, Object... args)
      Logs a throwable that happened. Adds the stack trace to the log.
      Parameters:
      level - The level.
      t - The throwable that should be logged.
      pattern - The formatted message to print.
      args - The objects to insert into format string
      See Also:
    • logPrivate

      private static void logPrivate(Level level, String pattern, Object... args)
    • logPrivate

      private static void logPrivate(Level level, String message)
    • logPrivate

      private static void logPrivate(Level level, Supplier<String> supplier)
    • isLoggingEnabled

      public static boolean isLoggingEnabled(Level level)
      Tests if a given log level is enabled. This can be used to avoid constructing debug data if required. For formatting text, you should use the debug(String, Object...) message
      Parameters:
      level - A level constant. You can e.g. use LEVEL_ERROR
      Returns:
      true if log level is enabled.
    • isDebugEnabled

      public static boolean isDebugEnabled()
      Determines if debug log level is enabled. Useful to avoid costly construction of debug messages when not enabled.
      Returns:
      true if log level is at least debug, false otherwise
      Since:
      12620
    • isTraceEnabled

      public static boolean isTraceEnabled()
      Determines if trace log level is enabled. Useful to avoid costly construction of trace messages when not enabled.
      Returns:
      true if log level is at least trace, false otherwise
      Since:
      12620
    • getErrorLog

      private static String getErrorLog(String message, Throwable t)
    • getErrorLogWithStack

      private static String getErrorLogWithStack(String message, Throwable t)
    • getErrorMessage

      public static String getErrorMessage(Throwable t)
      Returns a human-readable message of error, also usable for developers.
      Parameters:
      t - The error
      Returns:
      The human-readable error message
    • clearLastErrorAndWarnings

      public static void clearLastErrorAndWarnings()
      Clear the list of last warnings
    • getLastErrorAndWarnings

      Get the last error and warning messages in the order in which they were received.
      Returns:
      The last errors and warnings.
    • getLogger

      public static Logger getLogger()
      Provides direct access to the logger used. Use of methods like warn(String) is preferred.
      Returns:
      The logger