Add Entry to the Audit Log


#1

Hi,

I am struggling a little bit with the Audit Log. I am trying to add an event to the Audit Log but I do not know which interface to use.

This is what I got so far:

private static AuditManager auditManager;
    private static AuditRecordEntityFactory auditRecordEntityFactory;

    /**
     * Which manager, etc. could I use?
     * @return 
     */
    public static AuditManager getAuditManager() {
        //new DefaultAuditManager(auditRecordDao) how would I get this?
        if (auditManager == null) {
            auditManager = (AuditManager) ContainerManager.getComponent("auditManager");
        }
        return auditManager;
    }

    public static AuditRecordEntityFactory getAuditRecordEntityFactory() {
        if (auditRecordEntityFactory == null) {
            auditRecordEntityFactory = new AuditRecordEntityFactory(new DefaultI18NBeanFactory(), new DefaultLocaleManager());
        }
        return auditRecordEntityFactory;
    }

    public static void logClone(String name, String url) {     
        AuditRecord a = AuditRecord.builder().category("MyPlugin").affectedObject(AffectedObject.builder().objectType("object1").name(name).build()).changedValue(ChangedValue.builder().name("CLONE").build()).description("description").build();
        getAuditManager().storeRecord(getAuditRecordEntityFactory().fromAuditRecord(a));
    }

Any help would be greatly appreciated.


#2

Hi Dominik,
you could use AuditService instead of AuditManager:

import com.atlassian.confluence.api.service.audit.AuditService;

@Named
public class MyAuditRecorder {

	@ComponentImport
	private final AuditService auditService;

	@Autowired
	public MyAuditRecorder(final AuditService auditService) {
		this.auditService = auditService;
	}

	public void store(...) {
		AuditRecord record = new AuditRecord.Builder()....build();
		auditService.storeRecord(record);
	}
        ...

Worked at least well for us :slight_smile:
All best
Manuel


#3

Thanks, got it working now :wink: