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
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 double price;

View file

@ -39,6 +39,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.time.Instant;
import java.util.*;
import java.util.function.Consumer;
@ -324,12 +325,19 @@ public class PriceFeedService {
priceConsumer.accept(marketPrice.getPrice());
result = true;
} else {
errorMessage = "Price for currency " + currencyCode + " is outdated. marketPrice= " +
marketPrice + " priceProvider=" + baseUrl;
errorMessage = "Price for currency " + currencyCode + " is outdated by " +
(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 {
log.info("Market price for currency " + currencyCode + " is not provided by the provider " +
baseUrl + ". That is expected for currencies not listed at providers.");
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 " +
baseUrl + ". That is expected for currencies not listed at providers.");
result = true;
}
} catch (Throwable t) {