Class 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 Detail

      • 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.
    • Constructor Detail

    • Method Detail

      • 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​(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​(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​(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​(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​(Throwable t)
        Prints a trace message for the given Throwable if logging is on.
        Parameters:
        t - The throwable object causing the error.
        Since:
        12620
      • 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:
        logWithStackTrace(Level, Throwable)
      • 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
      • 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
      • getLastErrorAndWarnings

        public static List<StringgetLastErrorAndWarnings()
        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