Managing Logs
Log Management allows you to capture data, which help you understand the processes at runtime. In the Rule Engine and Promotion Engine, logging is implemented as an Aspect.
Using Aspect Oriented Programming (AOP)
allows you to have a separate class for logging while your functional classes are configured to call methods to achieve logging across the Rule Engine and the Promotion Engine. The following sections provide you detailed information on how logging is implemented.
Rule Engine
abstract class de.hybris.platform.ruleengineservices.aspect.LoggingAspect
-
Method isEligibleForJoinPoint(...) must be implemented in subclasses
-
Method(s) with Aspect annotations (for example, @Before) have to be implemented in subclasses to specify joint-points to intercept and call logJoinPoint(...) in it
-
Subclasses need to have @Aspect annotation to be able to act as Spring Aspect
-
The default log level defined in this class is <DEBUG>. To change it in a subclass, override getLogLevel() method
-
Format of the logged info is defined in getLogInfoFromArgs(...) method and can be overriden in subclasses
de.hybris.platform.droolsruleengineservices.aspect.RuleEvaluationLogger
-
Extends abstract LoggingAspect
-
Intercepts calls of public class methods in de.hybris.platform.droolsruleengineservices.rule.evaluation package and log it
-
Defines specific (different from default) format of the logged info
Promotion Engine
de.hybris.platform.promotionengineservices.aspect.ActionLogging
-
Extends abstract LoggingAspect
-
Intercepts calls of public class methods in de.hybris.platform.promotionengineservices.action.impl package and log it
Implementing Logging as an Aspect - Example
- Introduce a new class annotated with @Aspect (org.aspectj.lang.annotation.Aspect) that extends de.hybris.platform.ruleengineservices.aspect.AbstractLoggingAspect.
- Define Join Point Handlers. These refer to methods annotated with @Before with the org.aspectj.lang.JoinPoint that calls the logJoinPoint(joinPoint) method.
@Before("execution(public * de.hybris.platform.ruleengineservices.rule.evaluation.*.*(..))") public void decideBefore(final JoinPoint joinPoint) throws Throwable { logJoinPoint(joinPoint); } - Introduce boolean isEligibleForJoinPoint(final JoinPoint joinPoint) {...} method that defines which intercepted calls are eligible for logging (narrowing of the intercepted calls). The easiest option is to configure it to always return True. You can, however, customize it depending on the called class or method or parameters. All the information is available in the instance of the JoinPoint class.
- You can optionally introduce String getLogInfoFromArgs(final List<?> args) method to customize the formatting of the log output for the provided argument list of the intercepted method calls.