
com.dnastack.audit.logger.EmittingAuditEventLogger Maven / Gradle / Ivy
package com.dnastack.audit.logger;
import com.dnastack.audit.emitter.AuditEventLogEmitter;
import com.dnastack.audit.exception.AccumulatedEmitterException;
import com.dnastack.audit.model.AuditEventBody;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class EmittingAuditEventLogger implements AuditEventLogger {
private final List emitters;
public List getEmitters() {
return Collections.unmodifiableList(emitters);
}
public EmittingAuditEventLogger(List emitters) {
if (emitters == null || emitters.isEmpty()) {
throw new IllegalArgumentException("emitters must not be null or empty");
}
this.emitters = emitters;
}
@Override
public void log(AuditEventBody auditEvent) {
Objects.requireNonNull(auditEvent, "auditEvent must not be null");
Objects.requireNonNull(auditEvent.getContext().getTraceId(), "auditEvent trace id must not be null");
Objects.requireNonNull(auditEvent.getContext().getSpanId(), "auditEvent span id must not be null");
List accumulatedExceptions = new ArrayList<>();
emitters.forEach((emitter) -> {
try {
emitter.emit(auditEvent);
} catch (Exception ex) {
accumulatedExceptions.add(ex);
}
});
if (!accumulatedExceptions.isEmpty()) {
AccumulatedEmitterException accumulatedException = new AccumulatedEmitterException("Got exceptions during emitting logs");
accumulatedExceptions.forEach(accumulatedException::addSuppressed);
throw accumulatedException;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy