public final class Logging extends java.lang.Object
There are multiple log levels supported.
Modifier and Type | Class and Description |
---|---|
private static class |
Logging.RememberWarningHandler |
Modifier and Type | Field and Description |
---|---|
static java.util.logging.Level |
LEVEL_DEBUG
The josm internal log level to print debug output
|
static java.util.logging.Level |
LEVEL_ERROR
The josm internal log level indicating a severe error in the application that usually leads to a crash.
|
static java.util.logging.Level |
LEVEL_INFO
The josm internal log level to use for important events that will be useful when debugging problems
|
static java.util.logging.Level |
LEVEL_TRACE
The finest log level josm supports.
|
static java.util.logging.Level |
LEVEL_WARN
The josm internal log level to use when something that may lead to a crash or wrong behaviour has happened.
|
private static java.util.logging.Logger |
LOGGER |
private static Logging.RememberWarningHandler |
WARNINGS |
Modifier | Constructor and Description |
---|---|
private |
Logging() |
Modifier and Type | Method and Description |
---|---|
static void |
clearLastErrorAndWarnings()
Clear the list of last warnings
|
static void |
debug(java.lang.String message)
Prints a debug message if logging is on.
|
static void |
debug(java.lang.String pattern,
java.lang.Object... args)
Prints a formatted debug message if logging is on.
|
static void |
debug(java.lang.Throwable t)
Prints a debug message for the given Throwable if logging is on.
|
static void |
error(java.lang.String message)
Prints an error message if logging is on.
|
static void |
error(java.lang.String pattern,
java.lang.Object... args)
Prints a formatted error message if logging is on.
|
static void |
error(java.lang.Throwable t)
Prints an error message for the given Throwable if logging is on.
|
private static java.lang.String |
getErrorLog(java.lang.String message,
java.lang.Throwable t) |
private static java.lang.String |
getErrorLogWithStack(java.lang.String message,
java.lang.Throwable t) |
static java.lang.String |
getErrorMessage(java.lang.Throwable t)
Returns a human-readable message of error, also usable for developers.
|
static java.util.List<java.lang.String> |
getLastErrorAndWarnings()
Get the last error and warning messages in the order in which they were received.
|
static java.util.logging.Logger |
getLogger()
Provides direct access to the logger used.
|
static void |
info(java.lang.String message)
Prints a info message if logging is on.
|
static void |
info(java.lang.String pattern,
java.lang.Object... args)
Prints a formatted info message if logging is on.
|
static void |
info(java.lang.Throwable t)
Prints a info message for the given Throwable if logging is on.
|
static boolean |
isDebugEnabled()
Determines if debug log level is enabled.
|
static boolean |
isLoggingEnabled(java.util.logging.Level level)
Tests if a given log level is enabled.
|
static boolean |
isTraceEnabled()
Determines if trace log level is enabled.
|
static void |
log(java.util.logging.Level level,
java.lang.String message,
java.lang.Throwable t)
Logs a throwable that happened.
|
static void |
log(java.util.logging.Level level,
java.lang.Throwable t)
Logs a throwable that happened.
|
private static void |
logPrivate(java.util.logging.Level level,
java.lang.String message) |
private static void |
logPrivate(java.util.logging.Level level,
java.lang.String pattern,
java.lang.Object... args) |
private static void |
logPrivate(java.util.logging.Level level,
java.util.function.Supplier<java.lang.String> supplier) |
static void |
logWithStackTrace(java.util.logging.Level level,
java.lang.String message,
java.lang.Throwable t)
Logs a throwable that happened.
|
static void |
logWithStackTrace(java.util.logging.Level level,
java.lang.Throwable t)
Logs a throwable that happened.
|
static void |
logWithStackTrace(java.util.logging.Level level,
java.lang.Throwable t,
java.lang.String pattern,
java.lang.Object... args)
Logs a throwable that happened.
|
static void |
setLogLevel(java.util.logging.Level level)
Set the global log level.
|
static void |
trace(java.lang.String message)
Prints a trace message if logging is on.
|
static void |
trace(java.lang.String pattern,
java.lang.Object... args)
Prints a formatted trace message if logging is on.
|
static void |
trace(java.lang.Throwable t)
Prints a trace message for the given Throwable if logging is on.
|
static void |
warn(java.lang.String message)
Prints a warning message if logging is on.
|
static void |
warn(java.lang.String pattern,
java.lang.Object... args)
Prints a formatted warning message if logging is on.
|
static void |
warn(java.lang.Throwable t)
Prints a warning message for the given Throwable if logging is on.
|
public static final java.util.logging.Level LEVEL_ERROR
public static final java.util.logging.Level LEVEL_WARN
public static final java.util.logging.Level LEVEL_INFO
public static final java.util.logging.Level LEVEL_DEBUG
public static final java.util.logging.Level LEVEL_TRACE
private static final java.util.logging.Logger LOGGER
private static final Logging.RememberWarningHandler WARNINGS
private Logging()
public static void setLogLevel(java.util.logging.Level level)
level
- The log level to usepublic static void error(java.lang.String message)
message
- The message to print.public static void error(java.lang.String pattern, java.lang.Object... args)
MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition)
function to format text.pattern
- The formatted message to print.args
- The objects to insert into format string.public static void error(java.lang.Throwable t)
t
- The throwable object causing the error.public static void warn(java.lang.String message)
message
- The message to print.public static void warn(java.lang.String pattern, java.lang.Object... args)
MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition)
function to format text.pattern
- The formatted message to print.args
- The objects to insert into format string.public static void warn(java.lang.Throwable t)
t
- The throwable object causing the error.public static void info(java.lang.String message)
message
- The message to print.public static void info(java.lang.String pattern, java.lang.Object... args)
MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition)
function to format text.pattern
- The formatted message to print.args
- The objects to insert into format string.public static void info(java.lang.Throwable t)
t
- The throwable object causing the error.public static void debug(java.lang.String message)
message
- The message to print.public static void debug(java.lang.String pattern, java.lang.Object... args)
MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition)
function to format text.pattern
- The formatted message to print.args
- The objects to insert into format string.public static void debug(java.lang.Throwable t)
t
- The throwable object causing the error.public static void trace(java.lang.String message)
message
- The message to print.public static void trace(java.lang.String pattern, java.lang.Object... args)
MessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition)
function to format text.pattern
- The formatted message to print.args
- The objects to insert into format string.public static void trace(java.lang.Throwable t)
t
- The throwable object causing the error.public static void log(java.util.logging.Level level, java.lang.Throwable t)
level
- The level.t
- The throwable that should be logged.logWithStackTrace(Level, Throwable)
public static void log(java.util.logging.Level level, java.lang.String message, java.lang.Throwable t)
level
- The level.message
- An additional error messaget
- The throwable that caused the messagelogWithStackTrace(Level, String, Throwable)
public static void logWithStackTrace(java.util.logging.Level level, java.lang.Throwable t)
level
- The level.t
- The throwable that should be logged.log(Level, Throwable)
public static void logWithStackTrace(java.util.logging.Level level, java.lang.String message, java.lang.Throwable t)
level
- The level.message
- An additional error messaget
- The throwable that should be logged.logWithStackTrace(Level, Throwable)
public static void logWithStackTrace(java.util.logging.Level level, java.lang.Throwable t, java.lang.String pattern, java.lang.Object... args)
level
- The level.t
- The throwable that should be logged.pattern
- The formatted message to print.args
- The objects to insert into format stringlogWithStackTrace(Level, Throwable)
private static void logPrivate(java.util.logging.Level level, java.lang.String pattern, java.lang.Object... args)
private static void logPrivate(java.util.logging.Level level, java.lang.String message)
private static void logPrivate(java.util.logging.Level level, java.util.function.Supplier<java.lang.String> supplier)
public static boolean isLoggingEnabled(java.util.logging.Level level)
debug(String, Object...)
messagelevel
- A level constant. You can e.g. use LEVEL_ERROR
true
if log level is enabled.public static boolean isDebugEnabled()
true
if log level is at least debug, false
otherwisepublic static boolean isTraceEnabled()
true
if log level is at least trace, false
otherwiseprivate static java.lang.String getErrorLog(java.lang.String message, java.lang.Throwable t)
private static java.lang.String getErrorLogWithStack(java.lang.String message, java.lang.Throwable t)
public static java.lang.String getErrorMessage(java.lang.Throwable t)
t
- The errorpublic static void clearLastErrorAndWarnings()
public static java.util.List<java.lang.String> getLastErrorAndWarnings()
public static java.util.logging.Logger getLogger()
warn(String)
is prefered.