Skip to content

Commit

Permalink
logging: improve logging of payment operations
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
  • Loading branch information
pierre committed Apr 12, 2016
1 parent d01484c commit 3d995f0
Show file tree
Hide file tree
Showing 2 changed files with 319 additions and 49 deletions.
@@ -1,6 +1,6 @@
/*
* Copyright 2014-2015 Groupon, Inc
* Copyright 2014-2015 The Billing Project, LLC
* Copyright 2014-2016 Groupon, Inc
* Copyright 2014-2016 The Billing Project, LLC
*
* The Billing Project 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
Expand Down Expand Up @@ -32,19 +32,31 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;

public class DefaultApiBase {

private static final Logger log = LoggerFactory.getLogger(DefaultApiBase.class);
private static final Joiner JOINER = Joiner.on(",");

private final PaymentConfig paymentConfig;

public DefaultApiBase(final PaymentConfig paymentConfig) {
this.paymentConfig = paymentConfig;
}

protected void logAPICall(final String transactionType, final Account account, final UUID paymentMethodId, @Nullable final UUID paymentId, @Nullable final UUID transactionId, @Nullable final BigDecimal amount, @Nullable final Currency currency, @Nullable final String paymentExternalKey, @Nullable final String paymentTransactionExternalKey) {
protected void logAPICall(final String transactionType,
final Account account,
final UUID paymentMethodId,
@Nullable final UUID paymentId,
@Nullable final UUID transactionId,
@Nullable final BigDecimal amount,
@Nullable final Currency currency,
@Nullable final String paymentExternalKey,
@Nullable final String paymentTransactionExternalKey,
@Nullable final TransactionStatus transactionStatus,
@Nullable final List<String> paymentControlPluginNames) {
if (log.isInfoEnabled()) {
final StringBuilder logLine = new StringBuilder();
logLine.append("PaymentApi: transactionType='")
Expand Down Expand Up @@ -87,6 +99,16 @@ protected void logAPICall(final String transactionType, final Account account, f
.append(currency)
.append("'");
}
if (transactionStatus != null) {
logLine.append(", transactionStatus='")
.append(transactionStatus)
.append("'");
}
if (paymentControlPluginNames != null) {
logLine.append(", paymentControlPluginNames='")
.append(JOINER.join(paymentControlPluginNames))
.append("'");
}
log.info(logLine.toString());
}
}
Expand Down

1 comment on commit 3d995f0

@sbrossie
Copy link
Member

Choose a reason for hiding this comment

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

👍

Please sign in to comment.