- java.lang.Object
-
- eu.ess.xaos.core.util.LogUtils
-
public class LogUtils extends Object
Utilities for logging messages.- Author:
- claudio.rosati@esss.se
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
log(Logger logger, String className, String methodName, Level level, String message)
Log a message.static void
log(Logger logger, String className, String methodName, Level level, String message, Object... parameters)
Log a message.static void
log(Logger logger, String className, String methodName, Level level, Throwable thrown)
Log a message, with associatedThrowable
information.static void
log(Logger logger, String className, String methodName, Level level, Throwable thrown, String message)
Log a message, with associatedThrowable
information.static void
log(Logger logger, String className, String methodName, Level level, Throwable thrown, String message, Object... parameters)
Log a message, with associatedThrowable
information.static void
log(Logger logger, Level level, String message)
Log a message.static void
log(Logger logger, Level level, String message, Object... parameters)
Log a message.static void
log(Logger logger, Level level, Throwable thrown)
Log a message, with associatedThrowable
information.static void
log(Logger logger, Level level, Throwable thrown, String message)
Log a message, with associatedThrowable
information.static void
log(Logger logger, Level level, Throwable thrown, String message, Object... parameters)
Log a message, with associatedThrowable
information.static void
logTime(Logger logger, Level level, Runnable function, String startMessage, String endMessage, Object... args)
Logs the time spent executing the givenfunction
.static <T> T
logTime(Logger logger, Level level, Callable<T> function, String startMessage, String endMessage, Object... args)
Logs the time spent executing the givenfunction
.static void
logTimeSpent(Logger logger, Level level, long threshold, Runnable function, String message, Object... args)
Logs the time spent executing the givenfunction
.static <T> T
logTimeSpent(Logger logger, Level level, long threshold, Callable<T> function, String message, Object... args)
Logs the time spent executing the givenfunction
.static void
logTimeSpent(Logger logger, Level level, Runnable function, String message, Object... args)
Logs the time spent executing the givenfunction
.static <T> T
logTimeSpent(Logger logger, Level level, Callable<T> function, String message, Object... args)
Logs the time spent executing the givenfunction
.static void
registerHandle(Level level, LogHandler handler)
Associate aLogHandler
with the givenLevel
.static String
stackTrace(StackTraceElement[] trace)
Returns a string representation of the given stacktrace
.static void
unregisterHandle(Level level, LogHandler handler)
Removes a previously registeredLogHandler
.
-
-
-
Method Detail
-
log
public static void log(Logger logger, Level level, String message)
Log a message.- Parameters:
logger
- TheLogger
to log the message.level
- One of the message level identifiers, e.g.Level.SEVERE
.message
- The string message.
-
log
public static void log(Logger logger, String className, String methodName, Level level, String message)
Log a message.- Parameters:
logger
- TheLogger
to log the message.className
- The name of the class to be logged.methodName
- The name of the method to be logged.level
- One of the message level identifiers, e.g.Level.SEVERE
.message
- The string message. It can contains parameters.- See Also:
MessageFormat
-
log
public static void log(Logger logger, Level level, String message, Object... parameters)
Log a message.- Parameters:
logger
- TheLogger
to log the message.level
- One of the message level identifiers, e.g.Level.SEVERE
.message
- The string message. It can contains parameters.parameters
- Array of parameters to the message.- See Also:
MessageFormat
-
log
public static void log(Logger logger, String className, String methodName, Level level, String message, Object... parameters)
Log a message.- Parameters:
logger
- TheLogger
to log the message.className
- The name of the class to be logged.methodName
- The name of the method to be logged.level
- One of the message level identifiers, e.g.Level.SEVERE
.message
- The string message. It can contains parameters.parameters
- Array of parameters to the message.- See Also:
MessageFormat
-
log
public static void log(Logger logger, Level level, Throwable thrown)
Log a message, with associatedThrowable
information.- Parameters:
logger
- TheLogger
to log the message.level
- One of the message level identifiers, e.g.Level.SEVERE
.thrown
-Throwable
associated with log message.
-
log
public static void log(Logger logger, String className, String methodName, Level level, Throwable thrown)
Log a message, with associatedThrowable
information.- Parameters:
logger
- TheLogger
to log the message.className
- The name of the class to be logged.methodName
- The name of the method to be logged.level
- One of the message level identifiers, e.g.Level.SEVERE
.thrown
-Throwable
associated with log message.
-
log
public static void log(Logger logger, Level level, Throwable thrown, String message)
Log a message, with associatedThrowable
information.- Parameters:
logger
- TheLogger
to log the message.level
- One of the message level identifiers, e.g.Level.SEVERE
.thrown
-Throwable
associated with log message.message
- The string message.
-
log
public static void log(Logger logger, String className, String methodName, Level level, Throwable thrown, String message)
Log a message, with associatedThrowable
information.- Parameters:
logger
- TheLogger
to log the message.className
- The name of the class to be logged.methodName
- The name of the method to be logged.level
- One of the message level identifiers, e.g.Level.SEVERE
.thrown
-Throwable
associated with log message.message
- The string message. It can contains parameters.- See Also:
MessageFormat
-
log
public static void log(Logger logger, Level level, Throwable thrown, String message, Object... parameters)
Log a message, with associatedThrowable
information.- Parameters:
logger
- TheLogger
to log the message.level
- One of the message level identifiers, e.g.Level.SEVERE
.thrown
-Throwable
associated with log message.message
- The string message. It can contains parameters.parameters
- Array of parameters to the message.- See Also:
MessageFormat
-
log
public static void log(Logger logger, String className, String methodName, Level level, Throwable thrown, String message, Object... parameters)
Log a message, with associatedThrowable
information.- Parameters:
logger
- TheLogger
to log the message.className
- The name of the class to be logged.methodName
- The name of the method to be logged.level
- One of the message level identifiers, e.g.Level.SEVERE
.thrown
-Throwable
associated with log message.message
- The string message. It can contains parameters.parameters
- Array of parameters to the message.- See Also:
MessageFormat
-
logTime
public static void logTime(Logger logger, Level level, Runnable function, String startMessage, String endMessage, Object... args)
Logs the time spent executing the givenfunction
.- Parameters:
logger
- TheLogger
to log the message.level
- One of the message level identifiers, e.g.Level.SEVERE
.function
- The function whose execution time must be measured and logged.startMessage
- The start message to be logged. It can contains parameters, where parameter{0}
will always be substituted by the time this method is called (i.e. before the givenfunction
is started). Parameter{1}
indicates the first extra argument, parameter{2}
the second one, and so on.endMessage
- The message to be logged. It can contains parameters, where parameter{0}
will always be substituted by the time spent running the givenfunction
in seconds (double value). If not used, the time spent will be appended to themessage
. Parameter{1}
will be the start time, Parameter{2}
will be the end time. Parameter{3}
indicates the first extra argument, parameter{4}
the second one, and so on.args
- Arguments to be logged as parameters of messages.- See Also:
MessageFormat
,Instant.toString()
-
logTime
public static <T> T logTime(Logger logger, Level level, Callable<T> function, String startMessage, String endMessage, Object... args)
Logs the time spent executing the givenfunction
.- Type Parameters:
T
- The type of the return value.- Parameters:
logger
- TheLogger
to log the message.level
- One of the message level identifiers, e.g.Level.SEVERE
.function
- The function whose execution time must be measured and logged.startMessage
- The start message to be logged. It can contains parameters, where parameter{0}
will always be substituted by the time this method is called (i.e. before the givenfunction
is started). Parameter{1}
indicates the first extra argument, parameter{2}
the second one, and so on.endMessage
- The message to be logged. It can contains parameters, where parameter{0}
will always be substituted by the time spent running the givenfunction
in seconds (double value). If not used, the time spent will be appended to themessage
. Parameter{1}
will be the start time, Parameter{2}
will be the end time. Parameter{3}
indicates the first extra argument, parameter{4}
the second one, and so on.args
- Arguments to be logged as parameters of messages.- Returns:
- The value returned by the give
function
. - See Also:
MessageFormat
-
logTimeSpent
public static void logTimeSpent(Logger logger, Level level, Runnable function, String message, Object... args)
Logs the time spent executing the givenfunction
.- Parameters:
logger
- TheLogger
to log the message.level
- One of the message level identifiers, e.g.Level.SEVERE
.function
- The function whose execution time must be measured and logged.message
- The message to be logged. It can contains parameters, where parameter{0}
will always be substituted by the time spent running the givenfunction
in seconds (double value). If not used, the time spent will be appended to themessage
. Parameter{1}
will be the start time, Parameter{2}
will be the end time. Parameter{3}
indicates the first extra argument, parameter{4}
the second one, and so on.args
- Arguments to be logged as parameters ofmessage
.- See Also:
MessageFormat
-
logTimeSpent
public static void logTimeSpent(Logger logger, Level level, long threshold, Runnable function, String message, Object... args)
Logs the time spent executing the givenfunction
.- Parameters:
logger
- TheLogger
to log the message.level
- One of the message level identifiers, e.g.Level.SEVERE
.threshold
- The time spent executing the givenfunction
is logged only if it is larger than the threshold in milliseconds.function
- The function whose execution time must be measured and logged.message
- The message to be logged. It can contains parameters, where parameter{0}
will always be substituted by the time spent running the givenfunction
in seconds (double value). If not used, the time spent will be appended to themessage
. Parameter{1}
will be the start time, Parameter{2}
will be the end time. Parameter{3}
indicates the first extra argument, parameter{4}
the second one, and so on.args
- Arguments to be logged as parameters ofmessage
.- See Also:
MessageFormat
-
logTimeSpent
public static <T> T logTimeSpent(Logger logger, Level level, Callable<T> function, String message, Object... args)
Logs the time spent executing the givenfunction
.- Type Parameters:
T
- The type of the return value.- Parameters:
logger
- TheLogger
to log the message.level
- One of the message level identifiers, e.g.Level.SEVERE
.function
- The function whose execution time must be measured and logged.message
- The message to be logged. It can contains parameters, where parameter{0}
will always be substituted by the time spent running the givenfunction
in seconds (double value). If not used, the time spent will be appended to themessage
. Parameter{1}
will be the start time, Parameter{2}
will be the end time. Parameter{3}
indicates the first extra argument, parameter{4}
the second one, and so on.args
- Arguments to be logged as parameters ofmessage
.- Returns:
- The value returned by the give
function
. - See Also:
MessageFormat
-
logTimeSpent
public static <T> T logTimeSpent(Logger logger, Level level, long threshold, Callable<T> function, String message, Object... args)
Logs the time spent executing the givenfunction
.- Type Parameters:
T
- The type of the return value.- Parameters:
logger
- TheLogger
to log the message.level
- One of the message level identifiers, e.g.Level.SEVERE
.threshold
- The time spent executing the givenfunction
is logged only if it is larger than the threshold in milliseconds.function
- The function whose execution time must be measured and logged.message
- The message to be logged. It can contains parameters, where parameter{0}
will always be substituted by the time spent running the givenfunction
in seconds (double value). If not used, the time spent will be appended to themessage
. Parameter{1}
will be the start time, Parameter{2}
will be the end time. Parameter{3}
indicates the first extra argument, parameter{4}
the second one, and so on.args
- Arguments to be logged as parameters ofmessage
.- Returns:
- The value returned by the give
function
. - See Also:
MessageFormat
-
registerHandle
public static void registerHandle(Level level, LogHandler handler)
Associate aLogHandler
with the givenLevel
.Normally this method is called by this class' static initializer to register handlers provided by
LogHandlerProvider
s discovered at run-time.- Parameters:
level
- TheLevel
the given handler has to be associated with.handler
- The handler managing a message for the given level.
-
stackTrace
public static String stackTrace(StackTraceElement[] trace)
Returns a string representation of the given stacktrace
.- Parameters:
trace
- The stack trace array.- Returns:
- The string representation of the give stack trace.
- See Also:
Throwable.getStackTrace()
-
unregisterHandle
public static void unregisterHandle(Level level, LogHandler handler)
Removes a previously registeredLogHandler
.- Parameters:
level
- TheLevel
the given handler was associated with.handler
- The previously registered handler.- See Also:
registerHandle(java.util.logging.Level, eu.ess.xaos.core.util.LogHandler)
-
-