Package org.openstreetmap.josm.tools
Class Logging
java.lang.Object
org.openstreetmap.josm.tools.Logging
This class contains utility methods to log errors and warnings.
There are multiple log levels supported.
- Since:
- 10899
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAConsoleHandlerwith a couple of extra features, allowing it to be targeted at an an arbitraryOutputStreamwhich it can be asked to reacquire the reference for on demand throughLogging.ReacquiringConsoleHandler.reacquireOutputStream().private static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LevelThe josm internal log level to print debug outputstatic final LevelThe josm internal log level indicating a severe error in the application that usually leads to a crash.static final LevelThe josm internal log level to use for important events that will be useful when debugging problemsstatic final LevelThe finest log level josm supports.static final LevelThe josm internal log level to use when something that may lead to a crash or wrong behaviour has happened.private static final Loggerprivate static final Stopwatchprivate static final Logging.RememberWarningHandler -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClear the list of last warningsstatic voidPrints a debug message if logging is on.static voidPrints a formatted debug message if logging is on.static voidPrints a debug message for the given Throwable if logging is on.static voidPrints an error message if logging is on.static voidPrints a formatted error message if logging is on.static voidPrints an error message for the given Throwable if logging is on.private static StringgetErrorLog(String message, Throwable t) private static StringgetErrorLogWithStack(String message, Throwable t) static StringReturns a human-readable message of error, also usable for developers.Get the last error and warning messages in the order in which they were received.static LoggerProvides direct access to the logger used.static voidPrints a info message if logging is on.static voidPrints a formatted info message if logging is on.static voidPrints a info message for the given Throwable if logging is on.static booleanDetermines if debug log level is enabled.static booleanisLoggingEnabled(Level level) Tests if a given log level is enabled.static booleanDetermines if trace log level is enabled.static voidLogs a throwable that happened.static voidLogs a throwable that happened.private static voidlogPrivate(Level level, String message) private static voidlogPrivate(Level level, String pattern, Object... args) private static voidlogPrivate(Level level, Supplier<String> supplier) static voidlogWithStackTrace(Level level, String message, Throwable t) Logs a throwable that happened.static voidlogWithStackTrace(Level level, Throwable t) Logs a throwable that happened.static voidlogWithStackTrace(Level level, Throwable t, String pattern, Object... args) Logs a throwable that happened.static voidsetLogLevel(Level level) Set the global log level.static voidPrints a trace message if logging is on.static voidPrints a formatted trace message if logging is on.static voidPrints a trace message for the given Throwable if logging is on.static voidPrints a warning message if logging is on.static voidPrints a formatted warning message if logging is on.static voidPrints a warning message for the given Throwable if logging is on.
-
Field Details
-
LEVEL_ERROR
The josm internal log level indicating a severe error in the application that usually leads to a crash. -
LEVEL_WARN
The josm internal log level to use when something that may lead to a crash or wrong behaviour has happened. -
LEVEL_INFO
The josm internal log level to use for important events that will be useful when debugging problems -
LEVEL_DEBUG
The josm internal log level to print debug output -
LEVEL_TRACE
The finest log level josm supports. This lets josm print a lot of debug output. -
LOGGER
-
WARNINGS
-
startup
-
-
Constructor Details
-
Logging
private Logging()
-
-
Method Details
-
setLogLevel
Set the global log level.- Parameters:
level- The log level to use
-
error
Prints an error message if logging is on.- Parameters:
message- The message to print.
-
error
Prints a formatted error message if logging is on. CallsMessageFormat.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
Prints an error message for the given Throwable if logging is on.- Parameters:
t- The throwable object causing the error.- Since:
- 12620
-
warn
Prints a warning message if logging is on.- Parameters:
message- The message to print.
-
warn
Prints a formatted warning message if logging is on. CallsMessageFormat.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
Prints a warning message for the given Throwable if logging is on.- Parameters:
t- The throwable object causing the error.- Since:
- 12620
-
info
Prints a info message if logging is on.- Parameters:
message- The message to print.
-
info
Prints a formatted info message if logging is on. CallsMessageFormat.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
Prints a info message for the given Throwable if logging is on.- Parameters:
t- The throwable object causing the error.- Since:
- 12620
-
debug
Prints a debug message if logging is on.- Parameters:
message- The message to print.
-
debug
Prints a formatted debug message if logging is on. CallsMessageFormat.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
Prints a debug message for the given Throwable if logging is on.- Parameters:
t- The throwable object causing the error.- Since:
- 12620
-
trace
Prints a trace message if logging is on.- Parameters:
message- The message to print.
-
trace
Prints a formatted trace message if logging is on. CallsMessageFormat.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
Prints a trace message for the given Throwable if logging is on.- Parameters:
t- The throwable object causing the error.- Since:
- 12620
-
log
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
Logs a throwable that happened. The stack trace is not added to the log.- Parameters:
level- The level.message- An additional error messaget- The throwable that caused the message- See Also:
-
logWithStackTrace
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
Logs a throwable that happened. Adds the stack trace to the log.- Parameters:
level- The level.message- An additional error messaget- The throwable that should be logged.- See Also:
-
logWithStackTrace
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
-
logPrivate
-
logPrivate
-
isLoggingEnabled
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 thedebug(String, Object...)message- Parameters:
level- A level constant. You can e.g. useLEVEL_ERROR- Returns:
trueif log level is enabled.
-
isDebugEnabled
Determines if debug log level is enabled. Useful to avoid costly construction of debug messages when not enabled.- Returns:
trueif log level is at least debug,falseotherwise- Since:
- 12620
-
isTraceEnabled
Determines if trace log level is enabled. Useful to avoid costly construction of trace messages when not enabled.- Returns:
trueif log level is at least trace,falseotherwise- Since:
- 12620
-
getErrorLog
-
getErrorLogWithStack
-
getErrorMessage
Returns a human-readable message of error, also usable for developers.- Parameters:
t- The error- Returns:
- The human-readable error message
-
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
Provides direct access to the logger used. Use of methods likewarn(String)is preferred.- Returns:
- The logger
-