Improve logs

This commit is contained in:
Manfred Karrer 2018-01-25 22:45:10 -05:00
parent cca9a62e3a
commit 9027db5c29
No known key found for this signature in database
GPG key ID: 401250966A6B2C46
2 changed files with 13 additions and 5 deletions

View file

@ -23,7 +23,7 @@ import java.time.Instant;
@Value @Value
public class MarketPrice { public class MarketPrice {
private static final long MARKET_PRICE_MAX_AGE_SEC = 1800; // 30 min public static final long MARKET_PRICE_MAX_AGE_SEC = 1800; // 30 min
private final String currencyCode; private final String currencyCode;
private final double price; private final double price;

View file

@ -39,6 +39,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -324,10 +325,17 @@ public class PriceFeedService {
priceConsumer.accept(marketPrice.getPrice()); priceConsumer.accept(marketPrice.getPrice());
result = true; result = true;
} else { } else {
errorMessage = "Price for currency " + currencyCode + " is outdated. marketPrice= " + errorMessage = "Price for currency " + currencyCode + " is outdated by " +
marketPrice + " priceProvider=" + baseUrl; (Instant.now().getEpochSecond() - marketPrice.getTimestampSec()) / 60 + " minutes. " +
"Max. allowed age of price is " + MarketPrice.MARKET_PRICE_MAX_AGE_SEC / 60 + " minutes. " +
"priceProvider=" + baseUrl + ". " +
"marketPrice= " + marketPrice;
} }
} else { } else {
if (baseUrlOfRespondingProvider == null)
log.info("Market price for currency " + currencyCode + " was not delivered by provider " +
baseUrl + ". That is expected at startup.");
else
log.info("Market price for currency " + currencyCode + " is not provided by the provider " + log.info("Market price for currency " + currencyCode + " is not provided by the provider " +
baseUrl + ". That is expected for currencies not listed at providers."); baseUrl + ". That is expected for currencies not listed at providers.");
result = true; result = true;