添加日志
This commit is contained in:
1 parent
b6b9120b85
commit
d88ad8996a
3 files changed
+54
-1
No files matched your search
@@ -8,6 +8,55 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "rental.payment")
|
||||
public class RentalPaymentProperties {
|
||||
private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(RentalPaymentProperties.class);
|
||||
@org.springframework.beans.factory.annotation.Autowired
|
||||
private org.springframework.core.env.ConfigurableEnvironment environment;
|
||||
|
||||
/** 启动后输出实际绑定结果;不打印配置对象、URL、密钥或进程环境全集。 */
|
||||
@javax.annotation.PostConstruct
|
||||
public void logStartupConfiguration() {
|
||||
logConfiguration("STARTUP", "NILE");
|
||||
logConfiguration("STARTUP", "MAINNET");
|
||||
}
|
||||
|
||||
/** 每次创建前再次记录,区分部署实例、配置文件缺失和高优先级覆盖。 */
|
||||
public void logConfiguration(String diagnosticId, String network) {
|
||||
Channel selected = channel(network);
|
||||
LOG.info("充值配置诊断 diagnosticId={} network={} boundEnabled={} boundChannelEnabled={} activeProfiles={} defaultProfiles={} instance={}",
|
||||
diagnosticId, network, enabled, selected != null && selected.isEnabled(),
|
||||
environment == null ? "unavailable" : java.util.Arrays.toString(environment.getActiveProfiles()),
|
||||
environment == null ? "unavailable" : java.util.Arrays.toString(environment.getDefaultProfiles()),
|
||||
java.lang.management.ManagementFactory.getRuntimeMXBean().getName());
|
||||
if (environment == null) { return; }
|
||||
logSwitch(diagnosticId, "rental.enabled");
|
||||
logSwitch(diagnosticId, "rental.payment.enabled");
|
||||
logSwitch(diagnosticId, "rental.payment." + network.toLowerCase(java.util.Locale.ROOT) + ".enabled");
|
||||
logSwitch(diagnosticId, "RENT_PAYMENT_ENABLED");
|
||||
logSwitch(diagnosticId, "RENT_PAYMENT_" + network + "_ENABLED");
|
||||
// 常见错误层级仅报告是否存在,帮助发现把payment误写到根级的情况。
|
||||
LOG.info("充值配置层级检查 diagnosticId={} expectedPrefix=rental.payment legacyRootPaymentEnabledPresent={} legacyRootNetworkEnabledPresent={}",
|
||||
diagnosticId, environment.containsProperty("payment.enabled"),
|
||||
environment.containsProperty("payment." + network.toLowerCase(java.util.Locale.ROOT) + ".enabled"));
|
||||
}
|
||||
|
||||
private void logSwitch(String diagnosticId, String key) {
|
||||
String value;
|
||||
try {
|
||||
String resolved = environment.getProperty(key);
|
||||
value = resolved == null ? "ABSENT" : "true".equalsIgnoreCase(resolved.trim()) ? "TRUE"
|
||||
: "false".equalsIgnoreCase(resolved.trim()) ? "FALSE" : "NON_BOOLEAN";
|
||||
} catch (RuntimeException exception) { value = "RESOLUTION_FAILED"; }
|
||||
boolean found = false;
|
||||
// 按Spring优先级排列;首项为优先候选。只记录来源名称,不输出原始占位符值。
|
||||
for (org.springframework.core.env.PropertySource<?> source : environment.getPropertySources()) {
|
||||
if (source.containsProperty(key)) {
|
||||
LOG.info("充值开关来源 diagnosticId={} key={} resolved={} source={} firstCandidate={}",
|
||||
diagnosticId, key, value, source.getName().replaceAll("[\\r\\n]", "_"), !found);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) { LOG.info("充值开关来源 diagnosticId={} key={} resolved={} source=ABSENT", diagnosticId, key, value); }
|
||||
}
|
||||
private boolean enabled;
|
||||
private int connectTimeoutMs = 5000;
|
||||
private int readTimeoutMs = 15000;
|
||||
|
||||
@@ -46,12 +46,14 @@ public class RentalTopups {
|
||||
require(value.signum() > 0 && value.stripTrailingZeros().scale() <= 2, "充值金额必须为正数且最多两位小数");
|
||||
RentalPaymentProperties.Channel channel = config.channel(network);
|
||||
stage = "CHANNEL_CONFIG";
|
||||
config.logConfiguration(diagnosticId, network);
|
||||
LOG.info("充值通道检查 diagnosticId={} network={} enabled={} channelEnabled={} apiKeyConfigured={} apiSecretConfigured={} publicKeyConfigured={}",
|
||||
diagnosticId, network, config.isEnabled(), channel.isEnabled(),
|
||||
channel.getApiKey() != null && !channel.getApiKey().isEmpty(),
|
||||
channel.getApiSecret() != null && !channel.getApiSecret().isEmpty(),
|
||||
channel.getRsaPublicKeyLocation() != null && !channel.getRsaPublicKeyLocation().isEmpty());
|
||||
require(config.isEnabled() && channel.isEnabled(), "该网络暂未启用在线充值");
|
||||
require(config.isEnabled(), "在线充值总开关未启用,请检查rental.payment.enabled实际绑定值");
|
||||
require(channel.isEnabled(), network + "充值通道未启用,请检查rental.payment." + network.toLowerCase(Locale.ROOT) + ".enabled实际绑定值");
|
||||
require(value.compareTo(channel.getMinAmount()) >= 0 && value.compareTo(channel.getMaxAmount()) <= 0,
|
||||
"充值金额超出通道允许范围");
|
||||
URI base = URI.create(channel.getBaseUrl());
|
||||
|
||||
Reference in new issue
Block a user