日志记录提交
This commit is contained in:
@@ -8,17 +8,28 @@ import org.springframework.web.client.RestClient;
|
||||
* HTTP 审计输出实现,将结构化业务审计事件发送到独立审计服务。
|
||||
*/
|
||||
public class HttpAuditSink implements AuditSink {
|
||||
public static final String INTERNAL_SERVICE_TOKEN_HEADER = "X-Internal-Service-Token";
|
||||
private static final Logger auditLog = LoggerFactory.getLogger("BAIYUE_AUDIT");
|
||||
private final RestClient client;
|
||||
private final String endpoint;
|
||||
private final String internalServiceToken;
|
||||
|
||||
public HttpAuditSink(RestClient.Builder builder, String endpoint) {
|
||||
public HttpAuditSink(RestClient.Builder builder, String endpoint, String internalServiceToken) {
|
||||
this.client = builder.build();
|
||||
this.endpoint = endpoint;
|
||||
this.internalServiceToken = internalServiceToken;
|
||||
}
|
||||
|
||||
@Override public void publish(AuditEvent event) {
|
||||
try { client.post().uri(endpoint).body(event).retrieve().toBodilessEntity(); }
|
||||
@Override
|
||||
public void publish(AuditEvent event) {
|
||||
try {
|
||||
client.post()
|
||||
.uri(endpoint)
|
||||
.header(INTERNAL_SERVICE_TOKEN_HEADER, internalServiceToken)
|
||||
.body(event)
|
||||
.retrieve()
|
||||
.toBodilessEntity();
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
auditLog.warn("deliveryFailed errorType={} errorMessage={} audit={}",
|
||||
ex.getClass().getSimpleName(), ex.getMessage(), event);
|
||||
|
||||
Reference in New Issue
Block a user