Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Magnolia CMS provided you with default audit logging service where some major actions such as login, logout, activate and deactivate actions are logged. Follow the same principle with some additional integrations here, I would like to introduce an approach on how to implement some extra logging information with minimal affect impact on existing code base.

Table of Contents

Overview

An example use case is that we would like to log some info after execution of info.magnolia.importexport.command.JcrImportCommand where current implementation didn't provide any logging out of the box. We just don't want to alter existing code to include few lines of code, rebuild the whole bundle and redeploy them that takes us too much time and effort. Here we can find an easy way to achieve that with an affordable effort.

...

AspectJ load-time weaving can be enabled using AspectJ agent that can get involved in the class loading process and weave any types before they are defined in the VM. We specify the javaagent option to the JVM -javaagent:pathto/aspectjweaver.jar or using Maven plugin to configure the javaagent :

1
2
3
4
5
6
7
8
9
10
11
12
13
14

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.10</version>
    <configuration>
        <argLine>
            -javaagent:"${settings.localRepository}"/org/aspectj/
            aspectjweaver/${aspectj.version}/
            aspectjweaver-${aspectj.version}.jar
        </argLine>
        <useSystemClassLoader>true</useSystemClassLoader>
        <forkMode>always</forkMode>
    </configuration>
</plugin>

Verify your setup

Few lines of log should be printed out in your default log:

...