Java Reference
In-Depth Information
Now that you have collected the audit data, it has to be logged. You can adopt various
strategies to store this data. It can be stored in a database, filesystem, Microsoft Windows
Event Log, or Unix syslog. Hence, this component needs to be pluggable. I will follow the
simple principle of program to interface for this purpose. The AuditLog interface just
defines the single method log , which accepts an AuditEvent object. You can implement
this interface to provide a custom implementation. I have used an Apache Commons
Logger-based implementation to log the messages to the console, as shown in Listing 6-22.
Listing 6-22.
public class CommonsLoggingAuditLogImpl implements AuditLog{
private final Log _LOG = LogFactory.getLog(getClass());
public void log(AuditEvent event) {;
An instance of this logger is injected into the audit advices, as shown in Listing 6-23.
Listing 6-23. audit-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
xsi:schemaLocation=" ">
<!--advice -->
<bean name="auditAdvice"
<property name="auditLog" ref="auditLogger" />
<!- - other properties
<bean name="auditLogger" class="" />
<!—other beans -->
Search WWH ::

Custom Search