Class DebugLogger
Since not all logging methods have all context information themselves (for
instance the session token is not provided to each internal method), the
context information will be registered per thread. Logging without this
information will just use the last provided context information.
The context information will be set when
registering a
session as active. Since sessions are hierarchical and one session resp. its
subsessions may be registered several times. Therefore a stack is used for
the log record parameters. When
unregistering the
subsession, the last element will be popped from the stack.
Additionally a log context can be changed, that is some parameters can be changed intermediately. These changes can be undone completely and the original log context will be restored.
Besides the context information the logger also allows to adapt the source
class and method name. This can be used for logging when (un-)registering the
current session as start and finish logs but not logging the superclass but
the calling class and method. Setting the source class and name only applies
to the next call to log by the same thread.
Note that this logger is just a tiny wrapper to a normal logger and thus
completely outside the logger hierarchy. It does not have any parent or child
loggers.
- Author:
- Ulrich Kreher
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ThreadLocal<Stack<Pair<Object[],Object[]>>> The parameter stacks depending on the current thread.protected final ThreadLocal<Pair<String,String>> The source class name (first element) and the source method name for the next log-call of the current thread.protected final StringThe name of the service for which to log.protected final StringThe name of the service interface for which to log.Fields inherited from class de.aristaflow.adept2.util.logging.WrappingLogger
innerLoggerFields inherited from class java.util.logging.Logger
global, GLOBAL_LOGGER_NAME -
Constructor Summary
ConstructorsConstructorDescriptionDebugLogger(Class<?> serviceInterface, String serviceInstance, Logger innerLogger) Creates a new logger for adding several AristaFlow-specific parameters and the nanoseconds to log records.DebugLogger(String serviceInterface, String serviceInstance, Logger innerLogger) Creates a new logger for adding several AristaFlow-specific parameters and the nanoseconds to log records. -
Method Summary
Modifier and TypeMethodDescriptionvoidadaptNextSource(int stackElement) Sets the source class name and the source method for the next log record of the current thread.voidchangeLogContext(SessionToken session, QualifiedAgent tlAgent, QualifiedAgent agent, String arbString, UUID templID, UUID baseTemplID, UUID embdTemplID, UUID instID, EBPInstanceReference ebpIR) Changes the current log record parameter values intermediately for the designated session to the designated values.voidLogs the designated record by the wrapped logger in case the wrapped logger logs the corresponding level.voidregisterLogContext(SessionToken session, QualifiedAgent tlAgent, QualifiedAgent agent, String arbString, UUID templID, UUID baseTemplID, UUID embdTemplID, UUID instID, EBPInstanceReference ebpIR) Registers a new (sub-)session with the designated log record parameters.voidReverts the current changes of the log context registered for the current thread.protected voidsetLogParameters(Object[] logParameters, SessionToken session, QualifiedAgent tlAgent, QualifiedAgent agent, String arbString, UUID templID, UUID baseTemplID, UUID embdTemplID, UUID instID, EBPInstanceReference ebpIR) Sets the designated values as parameters for log records.voidUnregisters the session and the corresponding log context of the current thread from this logger, that is all log record parameters of the current subsession will be dropped from the parameter stack per (top-level) session.Methods inherited from class de.aristaflow.adept2.util.logging.WrappingLogger
addHandler, equals, getFilter, getHandlers, getLevel, getName, getParent, getResourceBundle, getResourceBundleName, getUseParentHandlers, hashCode, isLoggable, removeHandler, setFilter, setLevel, setLevel, setParent, setUseParentHandlersMethods inherited from class java.util.logging.Logger
config, config, entering, entering, entering, exiting, exiting, fine, fine, finer, finer, finest, finest, getAnonymousLogger, getAnonymousLogger, getGlobal, getLogger, getLogger, info, info, log, log, log, log, log, log, logp, logp, logp, logp, logp, logp, logrb, logrb, logrb, logrb, logrb, logrb, logrb, logrb, setResourceBundle, severe, severe, throwing, warning, warning
-
Field Details
-
logRecordParameters
The parameter stacks depending on the current thread. The first element of the pairs is the used log context, the second one is the original registered log context or null in case the log context has not been changed. -
recordSource
The source class name (first element) and the source method name for the next log-call of the current thread. -
serviceInstName
The name of the service for which to log. -
serviceIntName
The name of the service interface for which to log. For services this is usually the same as the logger name, but subservices may use their own class as logger name.
-
-
Constructor Details
-
DebugLogger
Creates a new logger for adding several AristaFlow-specific parameters and the nanoseconds to log records. All methods (except an initial part forlog(LogRecord)) will just be forwarded to the designated wrapped logger.- Parameters:
serviceInterface- The interface of the main service of this logger. This may benull.serviceInstance- The hierarchical name of the service instance. This may benull.innerLogger- The logger to which all requests will be forwarded.
-
DebugLogger
Creates a new logger for adding several AristaFlow-specific parameters and the nanoseconds to log records. All methods (except an initial part forlog(LogRecord)) will just be forwarded to the designated wrapped logger.- Parameters:
serviceInterface- The name of the interface of the main service of this logger. This may benull.serviceInstance- The hierarchical name of the service instance. This may benull.innerLogger- The logger to which all requests will be forwarded.
-
-
Method Details
-
log
Logs the designated record by the wrapped logger in case the wrapped logger logs the corresponding level. Otherwise the record is logged by the wrapping logger. AddsSystem.nanoTime()and AristaFlow-specific parameters (if available) to the log record. Additionally, the source class name and the source method name will be adapted. If they have beenset explicitlyboth will be unset afterwards.- Overrides:
login classWrappingLogger
-
adaptNextSource
public void adaptNextSource(int stackElement) Sets the source class name and the source method for the next log record of the current thread. This allows to adapt the source when logging in a super class but the log should resemble logging directly.
No logging context need to be registered for adapting the next source class name and source method name.- Parameters:
stackElement- The index of the stack element to use for the source class name and source method. 0 indicates the top of the stack, that is the most recent method which is always this method.
-
registerLogContext
public void registerLogContext(SessionToken session, QualifiedAgent tlAgent, QualifiedAgent agent, String arbString, UUID templID, UUID baseTemplID, UUID embdTemplID, UUID instID, EBPInstanceReference ebpIR) Registers a new (sub-)session with the designated log record parameters. A stack for the parameters will be created if needed and new log record parameters will be pushed to it. If one of the designated values is null, it will not be changed.- Parameters:
session- The session for which to create new log record parameters. This may be null.tlAgent- The agent of the top-level session token for the log record. This may be null.agent- The agent of the session token for the log record. This may be null.arbString- An arbitrary additional string for the log record allowing to sort and/or filter the log. This may benull.templID- The template ID for the log record. This may be null.baseTemplID- The base template ID for the log record. This may be null.embdTemplID- The (internal) ID of the embedded template ID the for the log record. This may be null.instID- The instance ID for the log record. This may be null.ebpIR- TheEBPInstanceReferencefor the log record. This may be null.- Throws:
InternalServiceException- If the designated session has not been registered yet, anInternalServiceExceptionwill be thrown.
-
changeLogContext
public void changeLogContext(SessionToken session, QualifiedAgent tlAgent, QualifiedAgent agent, String arbString, UUID templID, UUID baseTemplID, UUID embdTemplID, UUID instID, EBPInstanceReference ebpIR) Changes the current log record parameter values intermediately for the designated session to the designated values. If one of the designated values is null, it will not be changed.
The changes will be done on a copy of the original log context. This allows for reversible changes, that is one can restore the original context without needing to know it.- Parameters:
arbString- An arbitrary additional string for the log record allowing to sort and/or filter the log. This may benull.session- The session for the log record. This may be null.tlAgent- The agent of the top-level session token for the log record. This may be null.agent- The agent of the session token for the log record. This may be null.templID- The template ID for the log record. This may be null.baseTemplID- The base template ID for the log record. This may be null.embdTemplID- The (internal) ID of the embedded template ID the for the log record. This may be null.instID- The instance ID for the log record. This may be null.ebpIR- TheEBPInstanceReferencefor the log record. This may be null.- Throws:
InternalServiceException- If the designated session (or no log context for the current thread) has not been registered yet, anInternalServiceExceptionwill be thrown.
-
revertLogContextChanges
public void revertLogContextChanges()Reverts the current changes of the log context registered for the current thread. This restores the original log context and removes the changed log context completely.
Note that this method will be a no-op if there have not been any changes to the log context - instead of throwing an exception.- Throws:
InternalServiceException- If no log context for the current thread has not been registered yet, anInternalServiceExceptionwill be thrown.
-
unregisterLogContext
public void unregisterLogContext()Unregisters the session and the corresponding log context of the current thread from this logger, that is all log record parameters of the current subsession will be dropped from the parameter stack per (top-level) session. -
setLogParameters
protected void setLogParameters(Object[] logParameters, SessionToken session, QualifiedAgent tlAgent, QualifiedAgent agent, String arbString, UUID templID, UUID baseTemplID, UUID embdTemplID, UUID instID, EBPInstanceReference ebpIR) Sets the designated values as parameters for log records. If one of the designated values is null, it will not be changed. Besides the service instance name and the service interface name will be added to the log record.- Parameters:
logParameters- The array in which to set the designated values. This must not be null.session- The session for the log record. This may be null.tlAgent- The agent of the top-level session token for the log record. This may be null.agent- The agent of the session token for the log record. This may be null.arbString- An arbitrary additional string for the log record allowing to sort and/or filter the log. This may benull.templID- The template ID for the log record. This may be null.baseTemplID- The base template ID for the log record. This may be null.embdTemplID- The (internal) ID of the embedded template ID the for the log record. This may be null.instID- The instance ID for the log record. This may be null.ebpIR- TheEBPInstanceReferencefor the log record. This may be null.
-