FANNG1 commented on code in PR #4575: URL: https://github.com/apache/gravitino/pull/4575#discussion_r1724910883
########## core/src/main/java/org/apache/gravitino/audit/AuditLogManager.java: ########## @@ -0,0 +1,90 @@ +package org.apache.gravitino.audit; + +import com.google.common.annotations.VisibleForTesting; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.apache.gravitino.exceptions.GravitinoRuntimeException; +import org.apache.gravitino.listener.EventListenerManager; +import org.apache.gravitino.listener.api.EventListenerPlugin; +import org.apache.gravitino.listener.api.event.Event; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AuditLogManager { + + private static final Logger LOG = LoggerFactory.getLogger(AuditLogManager.class); + + @VisibleForTesting private AuditLogWriter auditLogWriter; + + public void init(Map<String, String> properties, EventListenerManager eventBusManager) { + LOG.info("Audit log properties {}", properties); + AuditLogConfig auditLogConfig = new AuditLogConfig(properties); + if (!auditLogConfig.isAuditEnabled()) { + LOG.warn("Audit log is not enabled"); + return; + } + + LOG.info("Audit log config {}", auditLogConfig); + String writerClassName = auditLogConfig.getWriterClassName(); + String formatterClassName = auditLogConfig.getAuditLogFormatterClassName(); + Formatter formatter = loadFormatter(formatterClassName); + LOG.info("Audit log writer class name {}", writerClassName); + if (StringUtils.isEmpty(writerClassName)) { + throw new GravitinoRuntimeException("Audit log writer class is not configured"); + } + + auditLogWriter = + loadAuditLogWriter( + writerClassName, auditLogConfig.getWriterProperties(properties), formatter); + + eventBusManager.addEventListener( + "audit-log", + new EventListenerPlugin() { + + @Override + public void init(Map<String, String> properties) throws RuntimeException {} + + @Override + public void start() throws RuntimeException {} + + @Override + public void stop() throws RuntimeException { + auditLogWriter.close(); + } + + @Override + public void onPostEvent(Event event) throws RuntimeException { + try { + auditLogWriter.write(event); + } catch (Exception e) { + throw new GravitinoRuntimeException(e, "Failed to write audit log"); Review Comment: it's critical to throw an exception here -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org