org.olat.core.logging.activity
Class ThreadLocalUserActivityLogger
java.lang.Object
org.olat.core.logging.activity.ThreadLocalUserActivityLogger
public class ThreadLocalUserActivityLogger
- extends java.lang.Object
Wrapper around a ThreadLocal holding a IUserActivityLogger.
The ThreadLocalUserActivityLogger can be called any time during
event handling and in dispose in order to do
User Activity Logging - i.e. to call the log() method.
The idea of the ThreadLocalUserActivityLogger is to avoid
having to pass all sorts of resource objects between Controller
and Manager methods for the sole purpose of having them available
at log time.
In the current design each Controller has a IUserActivityLogger
which is set up with the ThreadLocalUserActivityLogger's content
at Controller construction time (done in DefaultController).
Each Controller is then suggested to add LoggingResourcables
in the constructor - i.e. to add those resourceables which it knows
at construction time and which will be used later in its event()
methods to do logging.
With this simplification of having data (i.e. LoggingResourceables)
collected by a ThreadLocal one might easily loose oversight over
what exactly is set at what time where.
To help work around this the ILoggingAction/ResourceableTypeList
concept was introduced: it is a runtime safety check comparing
all the LoggingResourceables available in an IUserActivityLogger
versus what is in the businesPath and what the programmer knows
at implementation time as to which LoggingResourceables are mandatory
or optional.
Note that there is a Helper class called ThreadLocalUserActivityLoggerInstaller
which is a peer class working together with ThreadLocalUserActivityLogger
but was separated for logical reasons:
- The ThreadLocalUserActivityLogger mainly has two public functions:
the addLoggingResourceInfo and the log method: the OLAT developer
should mainly get in contact with these two method
- The ThreadLocalUserActivityLoggerInstaller's job though is to
set up/tear down IUserActivityLogger's at event handling time.
Initial Date: 21.10.2009
- Author:
- Stefan
- See Also:
ILoggingAction,
LoggingResourceable,
IUserActivityLogger,
ResourceableTypeList
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ThreadLocalUserActivityLogger
public ThreadLocalUserActivityLogger()
addLoggingResourceInfo
public static void addLoggingResourceInfo(ILoggingResourceable resourceInfo)
- Adds the given LoggingResourceInfo to the ThreadLocalUserActivityLogger.
Only use this method before Controller constructors - if you are
inside a Controller constructor and want to add a LoggingResourceable
to the Controller's IUserActivityLogger call DefaultController.addLoggingResourceInfo instead!
For temporarily adding/removing LoggingResourceInfos use one of the log() methods directly instead
- Parameters:
resourceInfo -
log
public static void log(ILoggingAction loggingAction,
java.lang.Class<?> callingClass,
ILoggingResourceable... loggingResourceables)
- Issues a log entry to the logging database based on the given loggingAction and
the loggingResourceables.
The loggingAction defines - besides the actual logMessage - which loggingResourceables
are expected and allowed to be logged alongside the logMessage.
If this check fails, a log.warn() is issued. This should then be fixed by either
adding the required loggingResourceable to the UserActivityLogger in the Controller's
constructor (preferred way) - or by passing it in this log call (less preferred way).
- Parameters:
loggingAction - the logging action which should be loggedcallingClass - the class which calls this log method - stored to the databaseloggingResourceables - optional and the less preferred way of passing
loggingResourceables to be stored alongside this log message to the database.
the preferred way though is to have it all added to the UserActivityLogger earlier -
that is, usually and typically in the Controller' constructor.
Preferred way of using loggingResourceables is via comma separated 'list'
setStickyActionType
public static void setStickyActionType(ActionType actionType)
- Sets the given ActionType 'sticky' to this Thread's ThreadLocal IUserActivityLogger -
i.e. when you set the sticky ActionType any ActionType passed along to
the log() method in the ILoggingAction is overwritten.
- Parameters:
actionType - the sticky ActionType which should overwrite
whatever comes in the ILoggingAction in log()
getStickyActionType
public static ActionType getStickyActionType()
- Gets 'sticky' ActionType of this Thread's ThreadLocal IUserActivityLogger - or null
if none is set