Package com.attivio.util
Class AttivioLogger
- java.lang.Object
-
- com.attivio.util.AttivioLogger
-
- All Implemented Interfaces:
StatusListener
public class AttivioLogger extends java.lang.Object implements StatusListener
Unifies all logging facilities through SLF4j with special handling for various features such as error codes and log message formatting.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAttivioLogger.ThreadLocalComponentNameThe thread local component name
-
Constructor Summary
Constructors Modifier Constructor Description protectedAttivioLogger(java.lang.String name)Creates the underlying logger.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddebug(java.lang.String msg, java.lang.Object... params)Logs a debug message.voiddebug(java.lang.Throwable t, java.lang.String msg, java.lang.Object... params)Logs a debug message with an exception.voidentering(java.lang.String sourceClass, java.lang.String sourceMethod)Logs an entering message at trace level.voidentering(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object... params)Logs an entering message at trace level.voiderror(AttivioException ae)Log an AttivioException at an error levelvoiderror(ErrorCode logMessageType, java.lang.String msg, java.lang.Object... params)Logs a error message with an error code.voiderror(ErrorCode logMessageType, java.lang.Throwable t, java.lang.String msg, java.lang.Object... params)Logs a severe message with an error code.voidexiting(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object result)Logs an entering message at trace level.static java.lang.StringformatLogMessage(java.lang.String msg, java.lang.Object... params)Safely formats a log message handling null input as well as returning a warning message if message formatting failed.static AttivioLogger.ThreadLocalComponentNamegetComponentNameHandle()static intgetErrorCount()java.lang.ObjectgetLoggedObject()Gets the specific object being logged.static AttivioLoggergetLogger(java.lang.Class<?> c)Gets a logger by class.static AttivioLoggergetLogger(java.lang.Object o)Gets a logger by object's class.static AttivioLoggergetLogger(java.lang.String name)Gets a logger by name.longgetMaxMessageLength()Gets the maximum message length.static intgetWarningCount()voidignoreException(ErrorCode logMessageType, java.lang.Throwable t, java.lang.String msg, java.lang.Object... args)Notes that an exception is being ignored at debug level.voidignoreException(java.lang.Throwable t)Notes that an exception is being ignored.voidignoreException(java.lang.Throwable t, java.lang.String msg, java.lang.Object... args)Notes that an exception is being ignored.voidinfo(java.lang.String msg, java.lang.Object... params)Logs an info message.booleanisAppendComponentName()booleanisDebugEnabled()Tells whether the DEBUG level is setbooleanisInfoEnabled()Tells whether the INFO level is setbooleanisTraceEnabled()Tells whether the TRACE level is setprotected java.lang.StringprepareMessage(java.lang.String original, java.lang.Object... params)Formats varargsvoidsetAppendComponentName(boolean appendComponentName)voidsetLoggedObject(java.lang.Object loggedObject)Sets the object being logged.voidsetMaxMessageLength(long maxMessageLength)Sets the maximum string length for log messages.voidtrace(java.lang.String msg, java.lang.Object... params)Logs a trace message.voidwarn(AttivioException ae)Log an AttivioException at a warning level.voidwarn(ErrorCode logMessageType, java.lang.String msg, java.lang.Object... params)Logs a warning message with an error code.voidwarn(ErrorCode logMessageType, java.lang.Throwable t, java.lang.String msg, java.lang.Object... params)Logs a warning message without an error code.
-
-
-
Method Detail
-
getLogger
public static final AttivioLogger getLogger(java.lang.String name)
Gets a logger by name.- Parameters:
name- name for logger- Returns:
- the logger for this name
-
getLogger
public static final AttivioLogger getLogger(java.lang.Class<?> c)
Gets a logger by class.- Parameters:
c- the class to use for naming conventions- Returns:
- the logger for this class/name
-
getLogger
public static final AttivioLogger getLogger(java.lang.Object o)
Gets a logger by object's class. The object used to create the logger becomes the loggedObject (seegetLoggedObject().- Parameters:
o- the object whose class to use for naming conventions- Returns:
- the logger for this class/name
-
trace
public void trace(java.lang.String msg, java.lang.Object... params)Logs a trace message.- Parameters:
msg- Message to logparams- variable arguments for the format string- See Also:
debug(String, Object...)
-
debug
public void debug(java.lang.String msg, java.lang.Object... params)Logs a debug message.- Specified by:
debugin interfaceStatusListener- Parameters:
msg- Message to logparams- variable arguments for the format string
-
debug
public void debug(java.lang.Throwable t, java.lang.String msg, java.lang.Object... params)Logs a debug message with an exception.- Parameters:
msg- Message to logparams- variable arguments for the format string
-
ignoreException
public void ignoreException(java.lang.Throwable t)
Notes that an exception is being ignored.- Parameters:
t- the exception being ignored
-
ignoreException
public void ignoreException(java.lang.Throwable t, java.lang.String msg, java.lang.Object... args)Notes that an exception is being ignored.- Parameters:
t- the exception being ignoredmsg- additional message about why this exception is being ignored.
-
ignoreException
public void ignoreException(ErrorCode logMessageType, java.lang.Throwable t, java.lang.String msg, java.lang.Object... args)
Notes that an exception is being ignored at debug level.- Parameters:
logMessageType-t- the exception being ignoredmsg- additional message about why this exception is being ignored.
-
info
public void info(java.lang.String msg, java.lang.Object... params)Logs an info message.- Specified by:
infoin interfaceStatusListener- Parameters:
msg- message to logparams- variable arguments for the format string
-
warn
public void warn(ErrorCode logMessageType, java.lang.Throwable t, java.lang.String msg, java.lang.Object... params)
Logs a warning message without an error code.- Specified by:
warnin interfaceStatusListener- Parameters:
logMessageType-msg- Message to logparams- variable arguments for the format string
-
warn
public void warn(ErrorCode logMessageType, java.lang.String msg, java.lang.Object... params)
Logs a warning message with an error code.- Specified by:
warnin interfaceStatusListener- Parameters:
logMessageType-msg- Message to logparams- variable arguments for the format string
-
warn
public void warn(AttivioException ae)
Log an AttivioException at a warning level.- Specified by:
warnin interfaceStatusListener- Parameters:
ae- the AttivioException
-
error
public void error(AttivioException ae)
Log an AttivioException at an error level- Parameters:
ae- The AttivioException
-
error
public void error(ErrorCode logMessageType, java.lang.String msg, java.lang.Object... params)
Logs a error message with an error code.- Parameters:
logMessageType-msg- Message to logparams- variable arguments for the format string
-
error
public void error(ErrorCode logMessageType, java.lang.Throwable t, java.lang.String msg, java.lang.Object... params)
Logs a severe message with an error code.- Specified by:
errorin interfaceStatusListener- Parameters:
logMessageType-t- Throwable to logmsg- Message to logparams- variable arguments for the format string
-
entering
public void entering(java.lang.String sourceClass, java.lang.String sourceMethod)Logs an entering message at trace level.- Parameters:
sourceClass- class namesourceMethod- method name
-
entering
public void entering(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object... params)Logs an entering message at trace level.- Parameters:
sourceClass- class namesourceMethod- method nameparams- method params
-
exiting
public void exiting(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object result)Logs an entering message at trace level.- Parameters:
sourceClass- class namesourceMethod- method nameresult- method result
-
prepareMessage
protected java.lang.String prepareMessage(java.lang.String original, java.lang.Object... params)Formats varargs- Parameters:
original- The original message being loggedparams- string format arguments- Returns:
- The formatted version of the message
-
getMaxMessageLength
public long getMaxMessageLength()
Gets the maximum message length.- Returns:
- maxMessageLength. Log messages longer than this length will be truncated.
-
setMaxMessageLength
public void setMaxMessageLength(long maxMessageLength)
Sets the maximum string length for log messages. Log messages longer than this length will be truncated. The minimum value for this parameter is 3.- Parameters:
maxMessageLength- the maximum message length
-
getLoggedObject
public java.lang.Object getLoggedObject()
Gets the specific object being logged. Will have a value if the logger was created viagetLogger(Object). If non-null, then the object id will appear in the log message. Allows for teasing apart log messages from multiple instances of a class.- Returns:
- the specific object being logged.
-
setLoggedObject
public void setLoggedObject(java.lang.Object loggedObject)
Sets the object being logged. SeegetLoggedObject().- Parameters:
loggedObject- the logged object
-
isTraceEnabled
public boolean isTraceEnabled()
Tells whether the TRACE level is set- Returns:
- true if TRACE level is set
-
isInfoEnabled
public boolean isInfoEnabled()
Tells whether the INFO level is set- Returns:
- true if INFO level is set
-
isDebugEnabled
public boolean isDebugEnabled()
Tells whether the DEBUG level is set- Returns:
- true if DEBUG level is set
-
getComponentNameHandle
public static AttivioLogger.ThreadLocalComponentName getComponentNameHandle()
-
isAppendComponentName
public boolean isAppendComponentName()
-
setAppendComponentName
public void setAppendComponentName(boolean appendComponentName)
-
getErrorCount
public static int getErrorCount()
- Returns:
- the number of errors that have been created since system startup.
-
getWarningCount
public static int getWarningCount()
- Returns:
- the number of warnings that have been created since system startup.
-
formatLogMessage
public static final java.lang.String formatLogMessage(java.lang.String msg, java.lang.Object... params)Safely formats a log message handling null input as well as returning a warning message if message formatting failed.In the event of a message format failure also log a message to the
AttivioLogger's class logger at the warning level to indicate an problem. This means that this method shoudl not be called until after Attivio properties have been read and the underlying logging system ahs been setup correctly.
-
-