Skip to content

Commit

Permalink
fix(): 消除external-type在启用monitor下但又未配置时的无用日志打印
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawven committed Oct 19, 2024
1 parent 573220e commit 212238b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.monitor.internal.exporter.AbstractApolloClientMetricsExporter;
import com.ctrip.framework.apollo.monitor.internal.exporter.ApolloClientMetricsExporter;
import com.ctrip.framework.apollo.monitor.internal.jmx.ApolloClientJmxMBeanRegister;
Expand Down Expand Up @@ -102,10 +103,14 @@ private static void initializeMetricsEventListener() {

private static void initializeMetricsExporter(
) {
if (StringUtils.isEmpty(m_configUtil.getMonitorExternalType()) || "NONE".equals(m_configUtil.
getMonitorExternalType())) {

Check warning on line 107 in apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java

View check run for this annotation

Codecov / codecov/patch

apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java#L107

Added line #L107 was not covered by tests
return;
}
ApolloClientMetricsExporterFactory exporterFactory = ApolloInjector.getInstance(
ApolloClientMetricsExporterFactory.class);
ApolloClientMetricsExporterFactory.class);
ApolloClientMetricsExporter metricsReporter = exporterFactory.getMetricsReporter(
MONITOR_CONTEXT.getApolloClientMonitorEventListeners());
MONITOR_CONTEXT.getApolloClientMonitorEventListeners());

Check warning on line 113 in apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java

View check run for this annotation

Codecov / codecov/patch

apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java#L113

Added line #L113 was not covered by tests
if (metricsReporter != null) {
MONITOR_CONTEXT.setApolloClientMetricsExporter(metricsReporter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void collect0(ApolloClientMonitorEvent event) {

private void putAttachmentValue(String argName, Object value) {
bootstrapArgs.put(argName, value);
bootstrapArgsString.put(argName, value.toString());
bootstrapArgsString.put(argName, value == null ? null : value.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@
* @date 2024/10/19
*/
public class DateUtil {

Check warning on line 26 in apollo-client/src/main/java/com/ctrip/framework/apollo/util/date/DateUtil.java

View check run for this annotation

Codecov / codecov/patch

apollo-client/src/main/java/com/ctrip/framework/apollo/util/date/DateUtil.java#L26

Added line #L26 was not covered by tests
public static DateTimeFormatter MEDIUM_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

public static String formatLocalDateTime(LocalDateTime localDateTime) {
return localDateTime.format(MEDIUM_FORMATTER);
}
public static final DateTimeFormatter MEDIUM_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

/**
* Formats a LocalDateTime object to a string using the MEDIUM_FORMATTER.
*
* @param localDateTime the LocalDateTime to format, can be null
* @return the formatted date-time string, or null if the input is null
*/
public static String formatLocalDateTime(LocalDateTime localDateTime) {
return localDateTime != null ? localDateTime.format(MEDIUM_FORMATTER) : null;
}
}

0 comments on commit 212238b

Please sign in to comment.