Getting an audit log uses the getAuditEntry method of the AuditApi.
For more information about this ReST API endpoint, see Get an Audit Entry (Log).
For a description of the common parameters, such as fields, see Common Parameters.
import org.alfresco.core.handler.AuditApi;
import org.alfresco.core.model.AuditEntryEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.List;
@Component
public class GetAuditLogCmd {
static final Logger LOGGER = LoggerFactory.getLogger(GetAuditLogCmd.class);
@Autowired
AuditApi auditApi;
public void execute(String auditAppId, String auditLogId) throws IOException {
List<String> fields = null;
AuditEntryEntry auditLog = auditApi.getAuditEntry(auditAppId, auditLogId, fields).getBody();
LOGGER.info("Got audit log metadata {}", auditLog);
}
}
Executing this code will list the audit logs for passed in audit app id. The audit log values have been trimmed:
% java -jar target/rest-api-0.0.1-SNAPSHOT.jar get-audit-log alfresco-access 80
2021-05-10 09:49:57.492 INFO 51645 --- [ main] o.a.tutorial.restapi.RestApiApplication : Started RestApiApplication in 3.49 seconds (JVM running for 3.992)
2021-05-10 09:49:57.494 INFO 51645 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[0]: get-audit-log
2021-05-10 09:49:57.496 INFO 51645 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[1]: alfresco-access
2021-05-10 09:49:57.496 INFO 51645 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[2]: 80
2021-05-10 09:49:57.676 INFO 51645 --- [ main] o.a.tutorial.restapi.GetAuditLogCmd : Got audit log metadata class AuditEntryEntry {
entry: class AuditEntry {
id: 80
auditApplicationId: alfresco-access
createdByUser: class UserInfo {
displayName: Administrator
id: admin
}
createdAt: 2021-05-10T08:27:12.270Z
values: {
/alfresco-access/transaction/sub-actions=updateNodeProperties,
/alfresco-access/transaction/properties/from={cm:lastThumbnailModification=[pdf:1620394371183, doclib:1620394374161], {http://www.alfresco.org/model/content/1.0}modified=2021-05-10T08:27:10.986+0000},
/alfresco-access/transaction/properties/to={cm:lastThumbnailModification=[doclib:1620394374161, pdf:1620635231931], {http://www.alfresco.org/model/content/1.0}modified=2021-05-10T08:27:11.935+0000},
/alfresco-access/transaction/path=/app:company_home/app:guest_home/cm:somefileudpated.txt,
/alfresco-access/transaction/action=updateNodeProperties,
/alfresco-access/transaction/type=cm:content,
/alfresco-access/transaction/user=admin}
}
}