net.sf.sasl.aop.logging
Class GenericLogAspect

java.lang.Object
  extended by net.sf.sasl.aop.AbstractRootAspect
      extended by net.sf.sasl.aop.AbstractPlaceholderScriptUsingAspect
          extended by net.sf.sasl.aop.logging.GenericLogAspect
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor, org.springframework.core.Ordered, org.springframework.core.PriorityOrdered

public class GenericLogAspect
extends AbstractPlaceholderScriptUsingAspect
implements org.aopalliance.intercept.MethodInterceptor

The task that this aspect addresses is to log informations in a generic way for the three different phases of a target method "call":

The log messages for the three different phases could be freely configured and also the loggers (and associated log levels) to which the log message should be passed.
The log messages could be placeholder scripts, which get interpreted by a placeholder script interpreter before the log message is passed to the configured loggers of a log configuration. Additional the aspect offers to add special placeholder script environment variable offerers that can pass variables to the placeholder script interpreters during a log session of target method call.
A default builtin setted "variable offerer" is the RuntimeBenchIEnvOfferer which offers the total runtime of a target method call as a variable.
Suppose you want to log which method is called and how long the runtime for that call was, additional all exceptions should get logged in a special exception log. Than a "simple" log configuration might look like the following.
<bean id="logAspect" class="net.sf.sasl.aop.logging.GenericLogAspect">
...
<property name="logConfiguration">
<list>

<!-- Configuration for logging the exception case of a target method execution-->
<bean class="net.sf.sasl.aop.logging.LogConfigBean">
<property name="executionPhaseSet">
<set>
<value>EXCEPTION</value>
</set>
</property>
<property name="logTextList">
<list>
<value>%exceptionStackTrace</value>
</list>
</property>
<property name="loggerConfigMap">
<map>
<entry key="de.example.ServiceCallLogger" value="ERROR" />
<entry key="de.example.ExceptionLogger" value="ERROR" />
</map>
</property>
</bean>

<!-- Configuration for logging call and runtime informations in success and exception case of the target method execution-->
<bean class="net.sf.sasl.aop.logging.LogConfigBean">
<property name="executionPhaseSet">
<set>
<value>SUCCESS</value>
<value>EXCEPTION</value>
</set>
</property>
<property name="logTextList">
<list>
<value>%targetClassName->%targetMethodName(%targetMethodParameterTypes) : %duration{'mm:ss.SSS', %iEnv{'runtimeBenchMillis'}}</value>
</list>
</property>
<property name="loggerConfigMap">
<map>
<entry key="de.example.ServiceCallLogger" value="INFO" />
</map>
</property>
</bean>

<!-- ... more configurations for example for tracing/debug ... -->

</list>
</property>

</bean>

The ServiceCallLogger log file will than have the following contained sample entry for the non exception case:
INFO 2010-05-13 10:58:39,562 [main] ServiceCallLogger - de.math.services.IntegralService ->computeIntegral(de.math.services.dto.FormulaDTO, de.math.services.dto.IntegrationBorderDTO) : 00:24.299

And the output for the exception case for the ExceptionLogger (and ServiceCallLogger) could be something like this:
ERROR 2010-05-13 11:04:42,437 [main] ExceptionLogger - e^(x^2) does not have an antiderivative.
at de.math.model.integration.Integrator
...

Since:
0.0.2 (sasl-common-aspect-library)
Author:
Philipp Förmer
See Also:
net.sf.sasl.aop.common.grammar.placeholder.resolver

Field Summary
 
Fields inherited from class net.sf.sasl.aop.AbstractPlaceholderScriptUsingAspect
placeholderSymbolTable
 
Fields inherited from class net.sf.sasl.aop.AbstractRootAspect
logger
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
GenericLogAspect()
           
 
Method Summary
protected  void doLogging(long sessionId, TargetMethodExecutionPhase executionPhase, org.aopalliance.intercept.MethodInvocation invocation, Object returnValue, Throwable occuredException)
          Does the logging for a (executionPhase, invocation, ...) tuple.
protected  void endLogSessionIEnvOfferer(long sessionId)
          Ends the log session identified with the session id at all registered interpreter environment variable offerer.
protected  Map<TargetMethodExecutionPhase,List<LogConfiguration>> getConfigurationLookupMap()
          Returns a copy of the (execution phase, log configurations) lookup map.
 List<ILogSessionIEnvOfferer> getLogSessionIEnvOffererList()
           
 Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
          Please see the class header javadoc for more informations what this method does.
protected  boolean isALoggerEnabledForConfiguration(Map<org.slf4j.Logger,LogLevel> loggerMap)
          Returns true, if there exists a logger in the map that is enabled for the associated log level.
protected  boolean isLoggerEnabledFor(org.slf4j.Logger logger, LogLevel logLevel)
          Returns true, if the given log level is enabled for the given logger.
protected  void logOverLogger(org.slf4j.Logger logger, LogLevel logLevel, String message)
          Logs a log message with the given log level over the given logger.
protected  void logOverLoggers(Map<org.slf4j.Logger,LogLevel> loggerMap, String message, boolean oneLogLinePerLine)
          Logs a log message over the all loggers which are contained in the map with the associated log level for each logger.
 void setLogConfiguration(List<LogConfigBean> configurationList)
          Sets a list of log configurations which define what and how should be logged by the aspect.
 void setLogSessionIEnvOffererList(List<ILogSessionIEnvOfferer> logSessionIEnvOffererList)
          Sets a list of interpreter environment variable offerer which can offer additional environment variables during a log session.
protected  void startLogSessionIEnvOfferer(long sessionId)
          Starts a new log session at all registered interpreter environment variable offerer with the given session id.
 
Methods inherited from class net.sf.sasl.aop.AbstractPlaceholderScriptUsingAspect
getPlaceholderSymbolTable, runInterpreter, setPlaceholderResolverList
 
Methods inherited from class net.sf.sasl.aop.AbstractRootAspect
getLogger, getOrder, setLogger, setLoggerByName, setOrder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericLogAspect

public GenericLogAspect()
Method Detail

invoke

public Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
              throws Throwable
Please see the class header javadoc for more informations what this method does.

Specified by:
invoke in interface org.aopalliance.intercept.MethodInterceptor
Throws:
Throwable
Since:
0.0.2 (sasl-common-aspect-library)
See Also:
MethodInterceptor.invoke(org.aopalliance.intercept.MethodInvocation)

startLogSessionIEnvOfferer

protected void startLogSessionIEnvOfferer(long sessionId)
Starts a new log session at all registered interpreter environment variable offerer with the given session id.

Parameters:
sessionId - any long value
Since:
0.0.2 (sasl-common-aspect-library)

endLogSessionIEnvOfferer

protected void endLogSessionIEnvOfferer(long sessionId)
Ends the log session identified with the session id at all registered interpreter environment variable offerer.

Parameters:
sessionId - any long value
Since:
0.0.2 (sasl-common-aspect-library)

doLogging

protected void doLogging(long sessionId,
                         TargetMethodExecutionPhase executionPhase,
                         org.aopalliance.intercept.MethodInvocation invocation,
                         Object returnValue,
                         Throwable occuredException)
                  throws InterpreterException
Does the logging for a (executionPhase, invocation, ...) tuple. The session id is used to retrieve the values from the interpreter environment variable offerer.

Parameters:
sessionId - any long value.
executionPhase - non null.
invocation - non null.
returnValue - null or non null.
occuredException - null or non null.
Throws:
InterpreterException - if an exeception occurs during interpreting the placeholder log script.
Since:
0.0.2 (sasl-common-aspect-library)

setLogConfiguration

public void setLogConfiguration(List<LogConfigBean> configurationList)
                         throws ParseException,
                                IllegalArgumentException
Sets a list of log configurations which define what and how should be logged by the aspect. Please see the LogConfigBean class for more details of which parts a log configuration exists and what those parts mean.
Null elements in the list will be ignored.

Parameters:
configurationList - non null.
Throws:
ParseException - if a parse error occurs during parsing the log texts as a placeholder script.
IllegalArgumentException - if configurationList is null.
Since:
0.0.2 (sasl-common-aspect-library)

getLogSessionIEnvOffererList

public List<ILogSessionIEnvOfferer> getLogSessionIEnvOffererList()
Returns:
non null copy of the interpreter environment variable offerer list.
Since:
0.0.2 (sasl-common-aspect-library)
See Also:
setLogSessionIEnvOffererList(List)

setLogSessionIEnvOffererList

public void setLogSessionIEnvOffererList(List<ILogSessionIEnvOfferer> logSessionIEnvOffererList)
                                  throws IllegalArgumentException
Sets a list of interpreter environment variable offerer which can offer additional environment variables during a log session. Such a "offerer" could be for example a stop watch, which offers the total runtime of a target method, after the target method finished its execution (successful or with an exception).

Parameters:
logSessionIEnvOffererList - non null.
Throws:
IllegalArgumentException - if logSessionIEnvOffererList is null.
Since:
0.0.2 (sasl-common-aspect-library)

getConfigurationLookupMap

protected Map<TargetMethodExecutionPhase,List<LogConfiguration>> getConfigurationLookupMap()
Returns a copy of the (execution phase, log configurations) lookup map. Changes to the log configuration lists may change the behavior of the component.

Returns:
non null map.
Since:
0.0.2 (sasl-common-aspect-library)

logOverLogger

protected void logOverLogger(org.slf4j.Logger logger,
                             LogLevel logLevel,
                             String message)
Logs a log message with the given log level over the given logger.

Parameters:
logger - non null
logLevel - non null
message - null or non null
Since:
0.0.2 (sasl-common-aspect-library)

logOverLoggers

protected void logOverLoggers(Map<org.slf4j.Logger,LogLevel> loggerMap,
                              String message,
                              boolean oneLogLinePerLine)
Logs a log message over the all loggers which are contained in the map with the associated log level for each logger. If the oneLogLinePerLine parameter is true than each line in the message will be logged separate over the loggers.

Parameters:
loggerMap - non null.
message - non null.
oneLogLinePerLine - true or false.
Since:
0.0.2 (sasl-common-aspect-library)

isLoggerEnabledFor

protected boolean isLoggerEnabledFor(org.slf4j.Logger logger,
                                     LogLevel logLevel)
Returns true, if the given log level is enabled for the given logger. False else.

Parameters:
logger - non null.
logLevel - non null.
Returns:
true or false.
Since:
0.0.2 (sasl-common-aspect-library)

isALoggerEnabledForConfiguration

protected boolean isALoggerEnabledForConfiguration(Map<org.slf4j.Logger,LogLevel> loggerMap)
Returns true, if there exists a logger in the map that is enabled for the associated log level. False else.

Parameters:
loggerMap - non null.
Returns:
true or false.
Since:
0.0.2 (sasl-common-aspect-library)


Copyright © 2010. All Rights Reserved.