public class LoggedUtils extends Object
Logged
annotation for configuring the logging behavior of a class.public void execute() { String logId = LoggedUtils.createLogId(); LoggedUtils.logEntry(log, logId, this); try { Object returnValue = executeCommand(); LoggedUtils.logReturn(log, logId, this, returnValue); return returnValue; } catch (Exception e) { LoggedUtils.logError(log, logId, this, e); throw e; } }
Modifier and Type | Field and Description |
---|---|
protected static String |
ENTRY_LOG
Log format for entry log message.
|
protected static String |
ERROR_LOG
Log format for exception log message with exception message.
|
protected static String |
EXIT_LOG_RETURN_VALUE
Log format for return log message with a return value.
|
protected static String |
EXIT_LOG_VOID
Log format for return log message with no return value.
|
Constructor and Description |
---|
LoggedUtils() |
Modifier and Type | Method and Description |
---|---|
protected static Object |
determineMessage(org.apache.commons.logging.Log log,
Logged logged,
Object obj)
Determine the message to print, according to whether the parameters should be expanded or not.
|
protected static Logged |
getAnnotation(Object obj)
Return the annotation present on the object's class.
|
static String |
getObjectId(Object obj)
Get the object (reference) id for an object.
|
protected static boolean |
isLogLevelOn(org.apache.commons.logging.Log log,
Logged.LogLevel logLevel)
Determine if the given log level is active for the given log.
|
protected static void |
log(LogCompat log,
Logged.LogLevel logLevel,
String message,
Object... parameters)
Log a message to the log, taking into account the log level (checking if it's active, and using it in the log).
|
static void |
logEntry(LogCompat log,
String id,
Object obj)
Log entry into a command to the given log, using the specification in the
Logged annotation on the
object's. |
static void |
logError(LogCompat log,
String id,
Object obj,
Throwable t)
Log error of a command to the given log, using the specification in the
Logged annotation on the
object's. |
static void |
logReturn(LogCompat log,
String id,
Object obj,
Object returnValue)
Log return of a command to the given log, using the specification in the
Logged annotation on the
object's. |
protected static final String ENTRY_LOG
protected static final String EXIT_LOG_VOID
protected static final String EXIT_LOG_RETURN_VALUE
protected static final String ERROR_LOG
public static String getObjectId(Object obj)
obj
- The object to get the id for (can be null
).null
it's 0).System.identityHashCode(Object)
public static void logEntry(LogCompat log, String id, Object obj)
Logged
annotation on the
object's. If there's no Logged
annotation present, or if the log level isn't sufficient to log, then
nothing happens.log
- The log to log to.id
- ID of the message, for finding the return message.obj
- The object to log for.public static void logReturn(LogCompat log, String id, Object obj, Object returnValue)
Logged
annotation on the
object's. If there's no Logged
annotation present, or if the log level isn't sufficient to log, then
nothing happens.log
- The log to log to.id
- ID of the message, for finding the entry message.obj
- The object to log for.public static void logError(LogCompat log, String id, Object obj, Throwable t)
Logged
annotation on the
object's. If there's no Logged
annotation present, or if the log level isn't sufficient to log, then
nothing happens.log
- The log to log to.id
- ID of the message, for finding the entry message.obj
- The object to log for.protected static void log(LogCompat log, Logged.LogLevel logLevel, String message, Object... parameters)
MessageFormat
specification, and they will undergo
transformation only if the log level is sufficient for the given log.log
- The log to log to.logLevel
- The log level (may not be null).message
- The message to log.parameters
- Optional parameters for the message.MessageFormat#format(Object[], StringBuffer, java.text.FieldPosition)
protected static Logged getAnnotation(Object obj)
obj
- The object to get the annotation for.Logged
annotation from the class, or null
if there isn't any.protected static boolean isLogLevelOn(org.apache.commons.logging.Log log, Logged.LogLevel logLevel)
log
- The log to check.logLevel
- The log level to check if active.protected static Object determineMessage(org.apache.commons.logging.Log log, Logged logged, Object obj)
log
- The log is needed to check if the parameters should be printed according to their level.logged
- The logging definition, for determining whether to expand the parameters or not.obj
- The object for which to get the message.Copyright © 2012. All Rights Reserved.