freesinger commented on code in PR #11343:
URL: https://github.com/apache/gravitino/pull/11343#discussion_r3341286178


##########
core/src/main/java/org/apache/gravitino/audit/JsonAuditFormatter.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.audit;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.json.JsonMapper;
+import com.google.common.collect.ImmutableSet;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import org.apache.gravitino.audit.v2.SimpleAuditLogV2;
+import org.apache.gravitino.listener.api.event.Event;
+import org.apache.gravitino.listener.api.event.ListEvent;
+
+/** Formatter that serializes audit logs as one JSON object per line. */
+public class JsonAuditFormatter implements Formatter {
+
+  @Override
+  public AuditLog format(Event event) {
+    return new JsonAuditLog(event);
+  }
+}
+
+final class JsonAuditLog extends SimpleAuditLogV2 {
+
+  private static final ObjectMapper OBJECT_MAPPER = 
JsonMapper.builder().build();
+
+  private static final DateTimeFormatter TIMESTAMP_FORMATTER =
+      
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").withZone(ZoneId.systemDefault());
+
+  private static final String REDACTED_VALUE = "***";
+
+  private static final Set<String> MASKED_CUSTOM_INFO_KEYS =
+      ImmutableSet.of(
+          "authorization", "cookie", "x-amz-security-token", 
"s3.access-key-id", "jdbc-password");

Review Comment:
   I extract an `AuditLogRedactor` class to do this stuff.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to