Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .claude/settings.local.json
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be git ignored. Need to run the excavator on OSS.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"permissions": {
"allow": [
"Bash(find:*)",
"WebFetch(domain:github.com)"
],
"deny": [],
"ask": []
}
}
44 changes: 27 additions & 17 deletions versions.lock
Original file line number Diff line number Diff line change
@@ -1,52 +1,64 @@
# Run ./gradlew writeVersionsLocks to regenerate this file. Blank lines are to minimize merge conflicts.

com.fasterxml.jackson.core:jackson-annotations:2.20 (5 constraints: a04a6e14)
com.fasterxml.jackson.core:jackson-annotations:2.20 (6 constraints: cb5a8b70)

com.fasterxml.jackson.core:jackson-core:2.20.0 (3 constraints: e83eeac9)
com.fasterxml.jackson.core:jackson-core:2.20.0 (4 constraints: 0c4fbc00)

com.fasterxml.jackson.core:jackson-databind:2.20.0 (5 constraints: 2f5a89ff)
com.fasterxml.jackson.core:jackson-databind:2.20.0 (5 constraints: 605a6554)

com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.20.0 (1 constraints: 3605333b)

com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.20.0 (1 constraints: 3605333b)

com.google.code.findbugs:jsr305:3.0.2 (1 constraints: 980fcc86)

com.google.errorprone:error_prone_annotations:2.41.0 (3 constraints: 3d2b05dd)
com.google.errorprone:error_prone_annotations:2.41.0 (7 constraints: 2d6991f5)

com.google.guava:failureaccess:1.0.3 (1 constraints: 160ae3b4)

com.google.guava:guava:33.5.0-jre (4 constraints: 3c56d911)
com.google.guava:guava:33.5.0-jre (5 constraints: 3c66d828)

com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918)

com.google.j2objc:j2objc-annotations:3.1 (1 constraints: b809f1a0)

com.palantir.conjure.java:conjure-lib:6.1.0 (1 constraints: 2718096d)
com.palantir.conjure.java:conjure-lib:8.50.0 (1 constraints: 5d187e85)

com.palantir.conjure.java.api:errors:2.19.0 (1 constraints: 2410a5a9)
com.palantir.conjure.java.api:errors:2.60.0 (1 constraints: 20109ea9)

com.palantir.gradle.idea-configuration:gradle-idea-configuration:0.3.0 (1 constraints: 0505f435)

com.palantir.ri:resource-identifier:1.5.0 (1 constraints: ee0f7499)
com.palantir.ri:resource-identifier:2.8.0 (1 constraints: f20f8299)

com.palantir.safe-logging:preconditions:1.18.0 (3 constraints: ed2dfa87)
com.palantir.safe-logging:logger:3.9.0 (2 constraints: 321c1dba)

com.palantir.safe-logging:safe-logging:1.18.0 (3 constraints: 54392cb5)
com.palantir.safe-logging:logger-slf4j:3.9.0 (1 constraints: 070e6e42)

com.palantir.tokens:auth-tokens:3.10.0 (1 constraints: 1c1090a9)
com.palantir.safe-logging:logger-spi:3.9.0 (2 constraints: 1d1e0c7c)

com.palantir.witchcraft.api:witchcraft-logging-api-objects:2.0.0 (1 constraints: 0405f535)
com.palantir.safe-logging:preconditions:3.9.0 (5 constraints: 274beb6a)

javax.annotation:javax.annotation-api:1.3.2 (1 constraints: f10f7399)
com.palantir.safe-logging:safe-logging:3.9.0 (7 constraints: ad751fd9)

javax.ws.rs:javax.ws.rs-api:2.1.1 (1 constraints: f10f7399)
com.palantir.tokens:auth-tokens:3.18.0 (1 constraints: 2410a8a9)

com.palantir.tritium:tritium-ids:0.101.0 (1 constraints: f50f7da6)

com.palantir.witchcraft.api:witchcraft-logging-api-objects:2.6.0 (1 constraints: 0a050736)

org.eclipse.collections:eclipse-collections:11.1.0 (1 constraints: 1b108aa9)

org.eclipse.collections:eclipse-collections-api:11.1.0 (2 constraints: f8229c26)

org.immutables:value:2.11.7 (1 constraints: c70f9196)

org.immutables:value-annotations:2.11.7 (1 constraints: 3d05393b)

org.jetbrains:annotations:26.0.2 (4 constraints: 3353f2c9)

org.jspecify:jspecify:1.0.0 (8 constraints: c9803ac0)

org.slf4j:slf4j-api:2.0.17 (3 constraints: 441db778)
org.slf4j:slf4j-api:2.0.17 (4 constraints: 8f2d4dcf)



Expand Down Expand Up @@ -84,8 +96,6 @@ org.hamcrest:hamcrest:2.2 (1 constraints: d20cdc04)

org.hamcrest:hamcrest-core:1.3 (1 constraints: cc05fe3f)

org.jetbrains:annotations:26.0.2 (1 constraints: d9190fdf)

org.junit.jupiter:junit-jupiter:6.0.1 (1 constraints: 48070970)

org.junit.jupiter:junit-jupiter-api:6.0.1 (6 constraints: ee6e221e)
Expand Down
2 changes: 1 addition & 1 deletion versions.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
com.fasterxml.jackson.*:* = 2.20.0
com.fasterxml.jackson.core:jackson-annotations = 2.20
com.palantir.witchcraft.api:* = 2.0.0
com.palantir.witchcraft.api:* = 2.6.0
com.google.guava:guava = 33.5.0-jre
org.immutables:* = 2.11.7
org.assertj:assertj-core = 3.27.6
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* (c) Copyright 2021 Palantir Technologies Inc. All rights reserved.
*
* Licensed 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 com.palantir.witchcraft.java.logging.format;

import com.palantir.witchcraft.api.logging.AuditLogV2;
import java.time.format.DateTimeFormatter;

final class AuditLogV2Formatter {
private AuditLogV2Formatter() {}

static String format(AuditLogV2 audit) {
return Formatting.withStringBuilder(buffer -> {
buffer.append('[');
DateTimeFormatter.ISO_INSTANT.formatTo(audit.getTime(), buffer);
buffer.append("] AUDIT: ").append(audit.getName()).append(' ').append(audit.getResult());

// Optional fields
audit.getUid().ifPresent(uid -> buffer.append(" uid: ").append(uid));
audit.getSid().ifPresent(sid -> buffer.append(" sid: ").append(sid));
audit.getTokenId().ifPresent(tokenId -> buffer.append(" tokenId: ").append(tokenId));
audit.getOrgId().ifPresent(orgId -> buffer.append(" orgId: ").append(orgId));
audit.getTraceId().ifPresent(traceId -> buffer.append(" traceId: ").append(traceId));
audit.getOrigin().ifPresent(origin -> buffer.append(" origin: ").append(origin));

if (!audit.getOtherUids().isEmpty()) {
buffer.append(" otherUids: ").append(audit.getOtherUids());
}

if (!audit.getRequestParams().isEmpty()) {
buffer.append("\n requestParams: ")
.append(Formatting.prettyPrintJson(audit.getRequestParams())
.replace("\n", "\n "));
}

if (!audit.getResultParams().isEmpty()) {
buffer.append("\n resultParams: ")
.append(Formatting.prettyPrintJson(audit.getResultParams())
.replace("\n", "\n "));
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* (c) Copyright 2021 Palantir Technologies Inc. All rights reserved.
*
* Licensed 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 com.palantir.witchcraft.java.logging.format;

import com.palantir.witchcraft.api.logging.AuditLogV3;
import java.time.format.DateTimeFormatter;

final class AuditLogV3Formatter {
private AuditLogV3Formatter() {}

static String format(AuditLogV3 audit) {
return Formatting.withStringBuilder(buffer -> {
buffer.append('[');
DateTimeFormatter.ISO_INSTANT.formatTo(audit.getTime(), buffer);
buffer.append("] AUDIT: ").append(audit.getName()).append(' ').append(audit.getResult());

// Product and service info
buffer.append(" product: ").append(audit.getProduct());
buffer.append(" productVersion: ").append(audit.getProductVersion());
audit.getStack().ifPresent(stack -> buffer.append(" stack: ").append(stack));
audit.getService().ifPresent(service -> buffer.append(" service: ").append(service));
audit.getHost().ifPresent(host -> buffer.append(" host: ").append(host));
audit.getDeployment()
.ifPresent(deployment -> buffer.append(" deployment: ").append(deployment));
audit.getEnvironment()
.ifPresent(environment -> buffer.append(" environment: ").append(environment));

// User and session info
audit.getUid().ifPresent(uid -> buffer.append(" uid: ").append(uid));
audit.getSid().ifPresent(sid -> buffer.append(" sid: ").append(sid));
audit.getTokenId().ifPresent(tokenId -> buffer.append(" tokenId: ").append(tokenId));
audit.getOrgId().ifPresent(orgId -> buffer.append(" orgId: ").append(orgId));
audit.getTraceId().ifPresent(traceId -> buffer.append(" traceId: ").append(traceId));
audit.getOrigin().ifPresent(origin -> buffer.append(" origin: ").append(origin));

// Categories
if (!audit.getCategories().isEmpty()) {
buffer.append(" categories: ").append(audit.getCategories());
}

// Event and log IDs
buffer.append(" eventId: ").append(audit.getEventId());
audit.getLogEntryId()
.ifPresent(logEntryId -> buffer.append(" logEntryId: ").append(logEntryId));
audit.getSequenceId()
.ifPresent(sequenceId -> buffer.append(" sequenceId: ").append(sequenceId));

if (!audit.getRequestFields().isEmpty()) {
buffer.append("\n requestFields: ")
.append(Formatting.prettyPrintJson(audit.getRequestFields())
.replace("\n", "\n "));
}

if (!audit.getResultFields().isEmpty()) {
buffer.append("\n resultFields: ")
.append(Formatting.prettyPrintJson(audit.getResultFields())
.replace("\n", "\n "));
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.palantir.witchcraft.java.logging.format;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.common.base.CharMatcher;
import java.util.Map;
import java.util.function.Consumer;
Expand All @@ -25,6 +28,8 @@ final class Formatting {

static final CharMatcher NEWLINE_MATCHER = CharMatcher.is('\n');

private static final ObjectMapper JSON_MAPPER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);

private static final ThreadLocal<StringBuilder> REUSABLE_STRING_BUILDER =
ThreadLocal.withInitial(() -> new StringBuilder(1024));

Expand Down Expand Up @@ -68,5 +73,16 @@ static String withStringBuilder(Consumer<StringBuilder> function) {
return result;
}

static String prettyPrintJson(Map<String, ?> map) {
if (map == null || map.isEmpty()) {
return "{}";
}
try {
return JSON_MAPPER.writeValueAsString(map);
} catch (JsonProcessingException e) {
return map.toString();
}
}

private Formatting() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.palantir.witchcraft.java.logging.format;

import com.palantir.witchcraft.api.logging.AuditLogV2;
import com.palantir.witchcraft.api.logging.AuditLogV3;
import com.palantir.witchcraft.api.logging.EventLogV2;
import com.palantir.witchcraft.api.logging.MetricLogV1;
import com.palantir.witchcraft.api.logging.RequestLogV2;
Expand Down Expand Up @@ -50,4 +52,14 @@ public Optional<String> metricV1(MetricLogV1 metricLogV1) {
public Optional<String> traceV1(TraceLogV1 traceLogV1) {
return Optional.of(TraceLogFormatter.format(traceLogV1));
}

@Override
public Optional<String> auditV2(AuditLogV2 auditLogV2) {
return Optional.of(AuditLogV2Formatter.format(auditLogV2));
}

@Override
public Optional<String> auditV3(AuditLogV3 auditLogV3) {
return Optional.of(AuditLogV3Formatter.format(auditLogV3));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.google.common.collect.ImmutableList;
import com.palantir.witchcraft.api.logging.AuditLogV2;
import com.palantir.witchcraft.api.logging.AuditLogV3;
import com.palantir.witchcraft.api.logging.DiagnosticLogV1;
import com.palantir.witchcraft.api.logging.EventLogV2;
import com.palantir.witchcraft.api.logging.MetricLogV1;
Expand All @@ -48,10 +49,11 @@ public final class LogParser<T> {
private static final String METRIC_V1 = "metric.1";
private static final String TRACE_V1 = "trace.1";
private static final String AUDIT_V2 = "audit.2";
private static final String AUDIT_V3 = "audit.3";
private static final String DIAGNOSTIC_V1 = "diagnostic.1";
private static final String WRAPPED_V1 = "wrapped.1";
private static final ImmutableList<String> LOG_TYPES = ImmutableList.of(
SERVICE_V1, REQUEST_V2, EVENT_V2, METRIC_V1, TRACE_V1, AUDIT_V2, DIAGNOSTIC_V1, WRAPPED_V1);
SERVICE_V1, REQUEST_V2, EVENT_V2, METRIC_V1, TRACE_V1, AUDIT_V2, AUDIT_V3, DIAGNOSTIC_V1, WRAPPED_V1);

private static final String WITCHCRAFT_LOG_PATTERN_STRING = "\\{.*?\"type\"\\s*?:\\s*?\"("
+ LOG_TYPES.stream().map(Pattern::quote).collect(Collectors.joining("|")) + ")\".*?}";
Expand Down Expand Up @@ -105,6 +107,9 @@ public Optional<T> tryParse(String logLine) {
case AUDIT_V2 -> {
return applyToLogLine(logLine, AuditLogV2.class, logVisitor::auditV2);
}
case AUDIT_V3 -> {
return applyToLogLine(logLine, AuditLogV3.class, logVisitor::auditV3);
}
case DIAGNOSTIC_V1 -> {
return applyToLogLine(logLine, DiagnosticLogV1.class, logVisitor::diagnosticV1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.palantir.witchcraft.java.logging.format;

import com.palantir.witchcraft.api.logging.AuditLogV2;
import com.palantir.witchcraft.api.logging.AuditLogV3;
import com.palantir.witchcraft.api.logging.DiagnosticLogV1;
import com.palantir.witchcraft.api.logging.EventLogV2;
import com.palantir.witchcraft.api.logging.MetricLogV1;
Expand Down Expand Up @@ -53,6 +54,10 @@ default Optional<T> auditV2(AuditLogV2 _auditLogV2) {
return defaultValue();
}

default Optional<T> auditV3(AuditLogV3 _auditLogV3) {
return defaultValue();
}

default Optional<T> diagnosticV1(DiagnosticLogV1 _diagnosticLogV1) {
return defaultValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.palantir.witchcraft.java.logging.format;

import com.palantir.witchcraft.api.logging.AuditLogV2;
import com.palantir.witchcraft.api.logging.AuditLogV3;
import com.palantir.witchcraft.api.logging.DiagnosticLogV1;
import com.palantir.witchcraft.api.logging.EventLogV2;
import com.palantir.witchcraft.api.logging.MetricLogV1;
Expand Down Expand Up @@ -63,6 +64,11 @@ public Optional<T> visitAuditLogV2(AuditLogV2 value) {
return logVisitor.auditV2(value);
}

@Override
public Optional<T> visitAuditLogV3(AuditLogV3 value) {
return logVisitor.auditV3(value);
}

@Override
public Optional<T> visitDiagnosticLogV1(DiagnosticLogV1 value) {
return logVisitor.diagnosticV1(value);
Expand Down
Loading