diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/core/HostReactor.java b/client/src/main/java/com/alibaba/nacos/client/naming/core/HostReactor.java index fa4a6a4c9..55adf287b 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/core/HostReactor.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/core/HostReactor.java @@ -105,6 +105,8 @@ public class HostReactor { return oldService; } + boolean changed = false; + if (oldService != null) { if (oldService.getLastRefTime() > serviceInfo.getLastRefTime()) { NAMING_LOGGER.warn("out of date data received, old-t: " + oldService.getLastRefTime() @@ -157,16 +159,19 @@ public class HostReactor { } if (newHosts.size() > 0) { + changed = true; NAMING_LOGGER.info("new ips(" + newHosts.size() + ") service: " + serviceInfo.getName() + " -> " + JSON.toJSONString(newHosts)); } if (remvHosts.size() > 0) { + changed = true; NAMING_LOGGER.info("removed ips(" + remvHosts.size() + ") service: " + serviceInfo.getName() + " -> " + JSON.toJSONString(remvHosts)); } if (modHosts.size() > 0) { + changed = true; NAMING_LOGGER.info("modified ips(" + modHosts.size() + ") service: " + serviceInfo.getName() + " -> " + JSON.toJSONString(modHosts)); } @@ -189,8 +194,10 @@ public class HostReactor { MetricsMonitor.getServiceInfoMapSizeMonitor().set(serviceInfoMap.size()); - NAMING_LOGGER.info("current ips:(" + serviceInfo.ipCount() + ") service: " + serviceInfo.getName() + - " -> " + JSON.toJSONString(serviceInfo.getHosts())); + if (changed) { + NAMING_LOGGER.info("current ips:(" + serviceInfo.ipCount() + ") service: " + serviceInfo.getName() + + " -> " + JSON.toJSONString(serviceInfo.getHosts())); + } return serviceInfo; } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/controller/OpsController.java b/config/src/main/java/com/alibaba/nacos/config/server/controller/OpsController.java index 4e588036d..6b9e24e7e 100755 --- a/config/src/main/java/com/alibaba/nacos/config/server/controller/OpsController.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/controller/OpsController.java @@ -22,6 +22,8 @@ import com.alibaba.nacos.config.server.constant.Constants; import com.alibaba.nacos.config.server.service.PersistService; import com.alibaba.nacos.config.server.service.dump.DumpService; +import com.alibaba.nacos.config.server.utils.LogUtil; +import com.alibaba.nacos.core.utils.WebUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -63,4 +65,13 @@ public class OpsController { return HttpServletResponse.SC_OK + ""; } + @RequestMapping(value = "/log", method = RequestMethod.PUT) + @ResponseBody + public String setLogLevel(HttpServletRequest request) { + String logName = WebUtils.required(request, "logName"); + String logLevel = WebUtils.required(request, "logLevel"); + LogUtil.setLogLevel(logName, logLevel); + return HttpServletResponse.SC_OK + ""; + } + } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/monitor/MemoryMonitor.java b/config/src/main/java/com/alibaba/nacos/config/server/monitor/MemoryMonitor.java index a0341e8bf..df466d7a3 100755 --- a/config/src/main/java/com/alibaba/nacos/config/server/monitor/MemoryMonitor.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/monitor/MemoryMonitor.java @@ -50,7 +50,7 @@ public class MemoryMonitor { } - static final long DELAY_SECONDS = 10; + private static final long DELAY_SECONDS = 10; @Scheduled(cron = "0 0 0 * * ?") public void clear() { @@ -89,9 +89,7 @@ class NotifyTaskQueueMonitorTask implements Runnable { @Override public void run() { int size = ((ScheduledThreadPoolExecutor)notifySingleService.getExecutor()).getQueue().size(); - memoryLog.info("notifySingleServiceThreadPool-{}, toNotifyTaskSize={}", - new Object[] {((ScheduledThreadPoolExecutor)notifySingleService.getExecutor()).getClass().getName(), - size}); + memoryLog.info("toNotifyTaskSize={}", size); MetricsMonitor.getNotifyTaskMonitor().set(size); } } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/BasicDataSourceServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/BasicDataSourceServiceImpl.java index df615adcd..2b2767a75 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/BasicDataSourceServiceImpl.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/BasicDataSourceServiceImpl.java @@ -302,7 +302,9 @@ public class BasicDataSourceServiceImpl implements DataSourceService { @Override public void run() { - defaultLog.info("check master db."); + if (defaultLog.isDebugEnabled()) { + defaultLog.debug("check master db."); + } boolean isFound = false; int index = -1; @@ -339,7 +341,9 @@ public class BasicDataSourceServiceImpl implements DataSourceService { @Override public void run() { - defaultLog.info("check db health."); + if (defaultLog.isDebugEnabled()) { + defaultLog.debug("check db health."); + } String sql = "SELECT * FROM config_info_beta WHERE id = 1"; for (int i = 0; i < testJTList.size(); i++) { diff --git a/config/src/main/java/com/alibaba/nacos/config/server/utils/LogUtil.java b/config/src/main/java/com/alibaba/nacos/config/server/utils/LogUtil.java index c4c9a8fe4..d03d1e779 100755 --- a/config/src/main/java/com/alibaba/nacos/config/server/utils/LogUtil.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/utils/LogUtil.java @@ -15,6 +15,7 @@ */ package com.alibaba.nacos.config.server.utils; +import ch.qos.logback.classic.Level; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,46 +29,74 @@ public class LogUtil { /** * 默认的日志 */ - static public final Logger defaultLog = LoggerFactory.getLogger("com.alibaba.nacos.config.startLog"); + public static final Logger defaultLog = LoggerFactory.getLogger("com.alibaba.nacos.config.startLog"); /** * 致命错误,需要告警 */ - static public final Logger fatalLog = LoggerFactory + public static final Logger fatalLog = LoggerFactory .getLogger("com.alibaba.nacos.config.fatal"); /** * 客户端GET方法获取数据的日志 */ - static public final Logger pullLog = LoggerFactory + public static final Logger pullLog = LoggerFactory .getLogger("com.alibaba.nacos.config.pullLog"); - static public final Logger pullCheckLog = LoggerFactory + public static final Logger pullCheckLog = LoggerFactory .getLogger("com.alibaba.nacos.config.pullCheckLog"); /** * 从DB dump数据的日志 */ - static public final Logger dumpLog = LoggerFactory + public static final Logger dumpLog = LoggerFactory .getLogger("com.alibaba.nacos.config.dumpLog"); - static public final Logger memoryLog = LoggerFactory + public static final Logger memoryLog = LoggerFactory .getLogger("com.alibaba.nacos.config.monitorLog"); - static public final Logger clientLog = LoggerFactory + public static final Logger clientLog = LoggerFactory .getLogger("com.alibaba.nacos.config.clientLog"); - static public final Logger sdkLog = LoggerFactory - .getLogger("com.alibaba.nacos.config.sdkLog"); - - static public final Logger traceLog = LoggerFactory + public static final Logger traceLog = LoggerFactory .getLogger("com.alibaba.nacos.config.traceLog"); - static public final Logger aclLog = LoggerFactory - .getLogger("com.alibaba.nacos.config.aclLog"); - - static public final Logger notifyLog = LoggerFactory + public static final Logger notifyLog = LoggerFactory .getLogger("com.alibaba.nacos.config.notifyLog"); - static public final Logger appCollectorLog = LoggerFactory - .getLogger("com.alibaba.nacos.config.appCollectorLog"); + public static void setLogLevel(String logName, String level) { + + switch (logName) { + case "config-server": + ((ch.qos.logback.classic.Logger) defaultLog).setLevel(Level.valueOf(level)); + break; + case "config-fatal": + ((ch.qos.logback.classic.Logger) fatalLog).setLevel(Level.valueOf(level)); + break; + case "config-pull": + ((ch.qos.logback.classic.Logger) pullLog).setLevel(Level.valueOf(level)); + break; + case "config-pull-check": + ((ch.qos.logback.classic.Logger) pullCheckLog).setLevel(Level.valueOf(level)); + break; + case "config-dump": + ((ch.qos.logback.classic.Logger) dumpLog).setLevel(Level.valueOf(level)); + break; + case "config-memory": + ((ch.qos.logback.classic.Logger) memoryLog).setLevel(Level.valueOf(level)); + break; + case "config-client-request": + ((ch.qos.logback.classic.Logger) clientLog).setLevel(Level.valueOf(level)); + break; + case "config-trace": + ((ch.qos.logback.classic.Logger) traceLog).setLevel(Level.valueOf(level)); + break; + case "config-notify": + ((ch.qos.logback.classic.Logger) notifyLog).setLevel(Level.valueOf(level)); + break; + default: + break; + } + + } + } diff --git a/distribution/conf/nacos-logback.xml b/distribution/conf/nacos-logback.xml index 716147944..44190b680 100644 --- a/distribution/conf/nacos-logback.xml +++ b/distribution/conf/nacos-logback.xml @@ -11,7 +11,7 @@ ${nacos.home}/logs/cmdb-main.log.%d{yyyy-MM-dd}.%i 2GB - 15 + 7 7GB true @@ -34,8 +34,8 @@ true ${LOG_HOME}/naming-server.log.%d{yyyy-MM-dd}.%i - 2GB - 15 + 1GB + 7 7GB true @@ -59,7 +59,7 @@ ${LOG_HOME}/naming-raft.log.%d{yyyy-MM-dd}.%i 1GB - 15 + 7 3GB true @@ -77,14 +77,14 @@ - - ${LOG_HOME}/naming-ephemeral.log + ${LOG_HOME}/naming-distro.log true - ${LOG_HOME}/naming-ephemeral.log.%d{yyyy-MM-dd}.%i + ${LOG_HOME}/naming-distro.log.%d{yyyy-MM-dd}.%i 1GB - 15 + 7 3GB true @@ -94,11 +94,11 @@ - + 0 1024 true - + ${LOG_HOME}/naming-event.log.%d{yyyy-MM-dd}.%i 1GB - 15 + 7 3GB true @@ -132,7 +132,7 @@ ${LOG_HOME}/naming-push.log.%d{yyyy-MM-dd}.%i 1GB - 15 + 7 3GB true @@ -148,7 +148,7 @@ ${LOG_HOME}/naming-rt.log.%d{yyyy-MM-dd}.%i 1GB - 15 + 7 3GB true @@ -165,7 +165,7 @@ ${LOG_HOME}/naming-performance.log.%d{yyyy-MM-dd}.%i 1GB - 15 + 7 3GB true @@ -175,109 +175,6 @@ - - ${LOG_HOME}/naming-router.log - true - - ${LOG_HOME}/naming-router.log.%d{yyyy-MM-dd}.%i - 2GB - 15 - 7GB - true - - - %date|%msg%n - UTF-8 - - - - - ${LOG_HOME}/naming-cache.log - true - - ${LOG_HOME}/naming-cache.log.%d{yyyy-MM-dd}.%i - 1GB - 15 - 3GB - true - - - %date|%msg%n - UTF-8 - - - - - ${LOG_HOME}/naming-device.log - true - - ${LOG_HOME}/naming-device.log.%d{yyyy-MM-dd}.%i - 2GB - 15 - 7GB - true - - - %date|%msg%n - UTF-8 - - - - - ${LOG_HOME}/naming-tag.log - true - - ${LOG_HOME}/naming-tag.log.%d{yyyy-MM-dd}.%i - 1GB - 15 - 3GB - true - - - %date %level %msg%n%n - UTF-8 - - - - - ${LOG_HOME}/naming-tenant.log - true - - ${LOG_HOME}/naming-tenant.log.%d{yyyy-MM-dd}.%i - 1GB - 15 - 3GB - true - - - %date %level %msg%n%n - UTF-8 - - - - - ${LOG_HOME}/naming-debug.log - true - - ${LOG_HOME}/naming-debug.log.%d{yyyy-MM-dd}.%i - 1GB - 15 - 3GB - true - - - %date %level %msg%n%n - UTF-8 - - - - @@ -286,7 +183,7 @@ ${LOG_HOME}/config-dump.log.%d{yyyy-MM-dd}.%i 2GB - 15 + 7 7GB true @@ -302,7 +199,7 @@ ${LOG_HOME}/config-pull.log.%d{yyyy-MM-dd}.%i 20MB - 15 + 7 128MB true @@ -318,7 +215,7 @@ ${LOG_HOME}/config-fatal.log.%d{yyyy-MM-dd}.%i 20MB - 15 + 7 128MB true @@ -334,7 +231,7 @@ ${LOG_HOME}/config-memory.log.%d{yyyy-MM-dd}.%i 20MB - 15 + 7 128MB true @@ -350,7 +247,7 @@ ${LOG_HOME}/config-pull-check.log.%d{yyyy-MM-dd}.%i 1GB - 15 + 7 3GB true @@ -360,23 +257,6 @@ - - ${LOG_HOME}/config-acl.log - true - - ${LOG_HOME}/config-acl.log.%d{yyyy-MM-dd}.%i - 50MB - 15 - 512MB - true - - - %date %level %msg%n%n - UTF-8 - - - ${LOG_HOME}/config-client-request.log @@ -384,7 +264,7 @@ ${LOG_HOME}/config-client-request.log.%d{yyyy-MM-dd}.%i 2GB - 15 + 7 7GB true @@ -394,23 +274,6 @@ - - ${LOG_HOME}/config-sdk-request.log - true - - ${LOG_HOME}/config-sdk-request.log.%d{yyyy-MM-dd}.%i - 1GB - 15 - 3GB - true - - - %date|%msg%n - UTF-8 - - - ${LOG_HOME}/config-trace.log @@ -418,7 +281,7 @@ ${LOG_HOME}/config-trace.log.%d{yyyy-MM-dd}.%i 2GB - 15 + 7 7GB true @@ -435,7 +298,7 @@ ${LOG_HOME}/config-notify.log.%d{yyyy-MM-dd}.%i 1GB - 15 + 7 3GB true @@ -445,23 +308,6 @@ - - ${LOG_HOME}/config-app.log - true - - ${LOG_HOME}/config-app.log.%d{yyyy-MM-dd}.%i - 20MB - 15 - 128MB - true - - - %date %level %msg%n%n - UTF-8 - - - ${LOG_HOME}/config-server.log @@ -469,7 +315,7 @@ ${LOG_HOME}/config-server.log.%d{yyyy-MM-dd}.%i 50MB - 15 + 7 512MB true @@ -486,7 +332,7 @@ ${LOG_HOME}/nacos.log.%d{yyyy-MM-dd}.%i 50MB - 15 + 7 512MB true @@ -503,7 +349,7 @@ ${LOG_HOME}/nacos-address.log.%d{yyyy-MM-dd}.%i 2GB - 15 + 7 7GB true @@ -531,9 +377,9 @@ - - - + + + @@ -551,22 +397,6 @@ - - - - - - - - - - - - - - - - @@ -589,21 +419,11 @@ - - - - - - - - - - @@ -614,11 +434,6 @@ - - - - - diff --git a/distribution/plugins/health/nacos-health-plugin-example-1.0.jar b/distribution/plugins/health/nacos-health-plugin-example-1.0.jar deleted file mode 100644 index 83542710f..000000000 Binary files a/distribution/plugins/health/nacos-health-plugin-example-1.0.jar and /dev/null differ diff --git a/naming/src/main/java/com/alibaba/nacos/naming/cluster/ServerListManager.java b/naming/src/main/java/com/alibaba/nacos/naming/cluster/ServerListManager.java index 5e53acec6..a474382c2 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/cluster/ServerListManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/cluster/ServerListManager.java @@ -95,15 +95,15 @@ public class ServerListManager { Loggers.SRV_LOG.warn("failed to get config: " + CLUSTER_CONF_FILE_PATH, e); } - if (Loggers.DEBUG_LOG.isDebugEnabled()) { - Loggers.DEBUG_LOG.debug("SERVER-LIST from cluster.conf: {}", result); + if (Loggers.SRV_LOG.isDebugEnabled()) { + Loggers.SRV_LOG.debug("SERVER-LIST from cluster.conf: {}", result); } //use system env if (CollectionUtils.isEmpty(serverList)) { serverList = SystemUtils.getIPsBySystemEnv(UtilsAndCommons.SELF_SERVICE_CLUSTER_ENV); - if (Loggers.DEBUG_LOG.isDebugEnabled()) { - Loggers.DEBUG_LOG.debug("SERVER-LIST from system variable: {}", result); + if (Loggers.SRV_LOG.isDebugEnabled()) { + Loggers.SRV_LOG.debug("SERVER-LIST from system variable: {}", result); } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DataSyncer.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DataSyncer.java index c5de7497a..2f9d53b87 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DataSyncer.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DataSyncer.java @@ -75,8 +75,8 @@ public class DataSyncer { String key = iterator.next(); if (StringUtils.isNotBlank(taskMap.putIfAbsent(buildKey(key, task.getTargetServer()), key))) { // associated key already exist: - if (Loggers.EPHEMERAL.isDebugEnabled()) { - Loggers.EPHEMERAL.debug("sync already in process, key: {}", key); + if (Loggers.DISTRO.isDebugEnabled()) { + Loggers.DISTRO.debug("sync already in process, key: {}", key); } iterator.remove(); } @@ -100,8 +100,8 @@ public class DataSyncer { List keys = task.getKeys(); - if (Loggers.EPHEMERAL.isDebugEnabled()) { - Loggers.EPHEMERAL.debug("sync keys: {}", keys); + if (Loggers.DISTRO.isDebugEnabled()) { + Loggers.DISTRO.debug("sync keys: {}", keys); } Map datumMap = dataStore.batchGet(keys); @@ -133,7 +133,7 @@ public class DataSyncer { } } catch (Exception e) { - Loggers.EPHEMERAL.error("sync data failed.", e); + Loggers.DISTRO.error("sync data failed.", e); } } }, delay); @@ -164,8 +164,8 @@ public class DataSyncer { try { - if (Loggers.EPHEMERAL.isDebugEnabled()) { - Loggers.EPHEMERAL.debug("server list is: {}", getServers()); + if (Loggers.DISTRO.isDebugEnabled()) { + Loggers.DISTRO.debug("server list is: {}", getServers()); } // send local timestamps to other servers: @@ -182,8 +182,8 @@ public class DataSyncer { return; } - if (Loggers.EPHEMERAL.isDebugEnabled()) { - Loggers.EPHEMERAL.debug("sync checksums: {}", keyChecksums); + if (Loggers.DISTRO.isDebugEnabled()) { + Loggers.DISTRO.debug("sync checksums: {}", keyChecksums); } for (Server member : getServers()) { @@ -193,7 +193,7 @@ public class DataSyncer { NamingProxy.syncCheckSums(keyChecksums, member.getKey()); } } catch (Exception e) { - Loggers.EPHEMERAL.error("timed sync task failed.", e); + Loggers.DISTRO.error("timed sync task failed.", e); } } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java index 9024addcb..83b338f73 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java @@ -111,7 +111,7 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService try { load(); } catch (Exception e) { - Loggers.EPHEMERAL.error("load data failed.", e); + Loggers.DISTRO.error("load data failed.", e); } } }); @@ -127,15 +127,15 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService // size = 1 means only myself in the list, we need at least one another server alive: while (serverListManager.getHealthyServers().size() <= 1) { Thread.sleep(1000L); - Loggers.EPHEMERAL.info("waiting server list init..."); + Loggers.DISTRO.info("waiting server list init..."); } for (Server server : serverListManager.getHealthyServers()) { if (NetUtils.localServer().equals(server.getKey())) { continue; } - if (Loggers.EPHEMERAL.isDebugEnabled()) { - Loggers.EPHEMERAL.debug("sync from " + server); + if (Loggers.DISTRO.isDebugEnabled()) { + Loggers.DISTRO.debug("sync from " + server); } // try sync data from remote server: if (syncAllDataFromRemote(server)) { @@ -194,7 +194,7 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService if (syncChecksumTasks.containsKey(server)) { // Already in process of this server: - Loggers.EPHEMERAL.warn("sync checksum task already in process with {}", server); + Loggers.DISTRO.warn("sync checksum task already in process with {}", server); return; } @@ -207,7 +207,7 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService for (Map.Entry entry : checksumMap.entrySet()) { if (distroMapper.responsible(KeyBuilder.getServiceName(entry.getKey()))) { // this key should not be sent from remote server: - Loggers.EPHEMERAL.error("receive responsible key timestamp of " + entry.getKey() + " from " + server); + Loggers.DISTRO.error("receive responsible key timestamp of " + entry.getKey() + " from " + server); // abort the procedure: return; } @@ -229,7 +229,9 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService } } - Loggers.EPHEMERAL.info("to remove keys: {}, to update keys: {}, source: {}", toRemoveKeys, toUpdateKeys, server); + if (Loggers.DISTRO.isDebugEnabled()) { + Loggers.DISTRO.info("to remove keys: {}, to update keys: {}, source: {}", toRemoveKeys, toUpdateKeys, server); + } for (String key : toRemoveKeys) { onRemove(key); @@ -243,7 +245,7 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService byte[] result = NamingProxy.getData(toUpdateKeys, server); processData(result); } catch (Exception e) { - Loggers.EPHEMERAL.error("get data from " + server + " failed!", e); + Loggers.DISTRO.error("get data from " + server + " failed!", e); } } finally { // Remove this 'in process' flag: @@ -259,7 +261,7 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService processData(data); return true; } catch (Exception e) { - Loggers.EPHEMERAL.error("sync full data from " + server + " failed!", e); + Loggers.DISTRO.error("sync full data from " + server + " failed!", e); return false; } } @@ -277,7 +279,7 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService // pretty sure the service not exist: if (switchDomain.isDefaultInstanceEphemeral()) { // create empty service - Loggers.EPHEMERAL.info("creating service {}", entry.getKey()); + Loggers.DISTRO.info("creating service {}", entry.getKey()); Service service = new Service(); String serviceName = KeyBuilder.getServiceName(entry.getKey()); String namespaceId = KeyBuilder.getNamespace(entry.getKey()); @@ -297,7 +299,7 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService if (!listeners.containsKey(entry.getKey())) { // Should not happen: - Loggers.EPHEMERAL.warn("listener of {} not found.", entry.getKey()); + Loggers.DISTRO.warn("listener of {} not found.", entry.getKey()); continue; } @@ -306,7 +308,7 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService listener.onChange(entry.getKey(), entry.getValue().value); } } catch (Exception e) { - Loggers.EPHEMERAL.error("[NACOS-DISTRO] error while execute listener of key: {}", entry.getKey(), e); + Loggers.DISTRO.error("[NACOS-DISTRO] error while execute listener of key: {}", entry.getKey(), e); continue; } @@ -374,7 +376,7 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService @Override public void run() { - Loggers.EPHEMERAL.info("distro notifier started"); + Loggers.DISTRO.info("distro notifier started"); while (true) { try { @@ -411,16 +413,16 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService continue; } } catch (Throwable e) { - Loggers.EPHEMERAL.error("[NACOS-DISTRO] error while notifying listener of key: {}", datumKey, e); + Loggers.DISTRO.error("[NACOS-DISTRO] error while notifying listener of key: {}", datumKey, e); } } - if (Loggers.EPHEMERAL.isDebugEnabled()) { - Loggers.EPHEMERAL.debug("[NACOS-DISTRO] datum change notified, key: {}, listener count: {}, action: {}", + if (Loggers.DISTRO.isDebugEnabled()) { + Loggers.DISTRO.debug("[NACOS-DISTRO] datum change notified, key: {}, listener count: {}, action: {}", datumKey, count, action.name()); } } catch (Throwable e) { - Loggers.EPHEMERAL.error("[NACOS-DISTRO] Error while handling notifying task", e); + Loggers.DISTRO.error("[NACOS-DISTRO] Error while handling notifying task", e); } } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/TaskDispatcher.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/TaskDispatcher.java index 23574beea..487766c97 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/TaskDispatcher.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/TaskDispatcher.java @@ -94,8 +94,8 @@ public class TaskDispatcher { String key = queue.poll(partitionConfig.getTaskDispatchPeriod(), TimeUnit.MILLISECONDS); - if (Loggers.EPHEMERAL.isDebugEnabled() && StringUtils.isNotBlank(key)) { - Loggers.EPHEMERAL.debug("got key: {}", key); + if (Loggers.DISTRO.isDebugEnabled() && StringUtils.isNotBlank(key)) { + Loggers.DISTRO.debug("got key: {}", key); } if (dataSyncer.getServers() == null || dataSyncer.getServers().isEmpty()) { @@ -124,8 +124,8 @@ public class TaskDispatcher { syncTask.setKeys(keys); syncTask.setTargetServer(member.getKey()); - if (Loggers.EPHEMERAL.isDebugEnabled() && StringUtils.isNotBlank(key)) { - Loggers.EPHEMERAL.debug("add sync task: {}", JSON.toJSONString(syncTask)); + if (Loggers.DISTRO.isDebugEnabled() && StringUtils.isNotBlank(key)) { + Loggers.DISTRO.debug("add sync task: {}", JSON.toJSONString(syncTask)); } dataSyncer.submit(syncTask, 0); @@ -135,7 +135,7 @@ public class TaskDispatcher { } } catch (Exception e) { - Loggers.EPHEMERAL.error("dispatch sync task failed.", e); + Loggers.DISTRO.error("dispatch sync task failed.", e); } } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftCore.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftCore.java index 715ad4d90..b0df814bb 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftCore.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftCore.java @@ -485,7 +485,9 @@ public class RaftCore { return; } - Loggers.RAFT.info("[RAFT] send beat with {} keys.", datums.size()); + if (Loggers.RAFT.isDebugEnabled()) { + Loggers.RAFT.debug("[RAFT] send beat with {} keys.", datums.size()); + } local.resetLeaderDue(); @@ -513,8 +515,6 @@ public class RaftCore { array.add(element); } - } else { - Loggers.RAFT.info("[RAFT] send beat only."); } packet.put("datums", array); @@ -531,13 +531,18 @@ public class RaftCore { byte[] compressedBytes = out.toByteArray(); String compressedContent = new String(compressedBytes, StandardCharsets.UTF_8); - Loggers.RAFT.info("raw beat data size: {}, size of compressed data: {}", - content.length(), compressedContent.length()); + + if (Loggers.RAFT.isDebugEnabled()) { + Loggers.RAFT.debug("raw beat data size: {}, size of compressed data: {}", + content.length(), compressedContent.length()); + } for (final String server : peers.allServersWithoutMySelf()) { try { final String url = buildURL(server, API_BEAT); - Loggers.RAFT.info("send beat to server " + server); + if (Loggers.RAFT.isDebugEnabled()) { + Loggers.RAFT.debug("send beat to server " + server); + } HttpClient.asyncHttpPostLarge(url, null, compressedBytes, new AsyncCompletionHandler() { @Override public Integer onCompleted(Response response) throws Exception { @@ -549,7 +554,9 @@ public class RaftCore { } peers.update(JSON.parseObject(response.getResponseBody(), RaftPeer.class)); - Loggers.RAFT.info("receive beat response from: {}", url); + if (Loggers.RAFT.isDebugEnabled()) { + Loggers.RAFT.debug("receive beat response from: {}", url); + } return 0; } @@ -615,8 +622,10 @@ public class RaftCore { List batch = new ArrayList<>(); if (!switchDomain.isSendBeatOnly()) { int processedCount = 0; - Loggers.RAFT.info("[RAFT] received beat with {} keys, RaftCore.datums' size is {}, remote server: {}, term: {}, local term: {}", - beatDatums.size(), datums.size(), remote.ip, remote.term, local.term); + if (Loggers.RAFT.isDebugEnabled()) { + Loggers.RAFT.debug("[RAFT] received beat with {} keys, RaftCore.datums' size is {}, remote server: {}, term: {}, local term: {}", + beatDatums.size(), datums.size(), remote.ip, remote.term, local.term); + } for (Object object : beatDatums) { processedCount = processedCount + 1; diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/DistroController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/DistroController.java index 080b98f6e..1f136dfde 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/DistroController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/DistroController.java @@ -74,7 +74,7 @@ public class DistroController { String entity = IOUtils.toString(request.getInputStream(), "UTF-8"); if (StringUtils.isBlank(entity)) { - Loggers.EPHEMERAL.error("[onSync] receive empty entity!"); + Loggers.DISTRO.error("[onSync] receive empty entity!"); throw new NacosException(NacosException.INVALID_PARAM, "receive empty entity!"); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java index b2e7e53c1..1afac6d40 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java @@ -234,8 +234,8 @@ public class InstanceController { String clusterName = clientBeat.getCluster(); - if (Loggers.DEBUG_LOG.isDebugEnabled()) { - Loggers.DEBUG_LOG.debug("[CLIENT-BEAT] full arguments: beat: {}, serviceName: {}", clientBeat, serviceName); + if (Loggers.SRV_LOG.isDebugEnabled()) { + Loggers.SRV_LOG.debug("[CLIENT-BEAT] full arguments: beat: {}, serviceName: {}", clientBeat, serviceName); } Instance instance = serviceManager.getInstance(namespaceId, serviceName, clientBeat.getCluster(), clientBeat.getIp(), @@ -372,8 +372,8 @@ public class InstanceController { Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { - if (Loggers.DEBUG_LOG.isDebugEnabled()) { - Loggers.DEBUG_LOG.debug("no instance to serve for service: " + serviceName); + if (Loggers.SRV_LOG.isDebugEnabled()) { + Loggers.SRV_LOG.debug("no instance to serve for service: " + serviceName); } result.put("name", serviceName); result.put("hosts", new JSONArray()); @@ -412,8 +412,8 @@ public class InstanceController { if (CollectionUtils.isEmpty(srvedIPs)) { - if (Loggers.DEBUG_LOG.isDebugEnabled()) { - Loggers.DEBUG_LOG.debug("no instance to serve for service: " + serviceName); + if (Loggers.SRV_LOG.isDebugEnabled()) { + Loggers.SRV_LOG.debug("no instance to serve for service: " + serviceName); } if (clientInfo.type == ClientInfo.ClientType.JAVA && diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/OperatorController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/OperatorController.java index 5de6e4d54..c0da0c7f3 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/OperatorController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/OperatorController.java @@ -29,10 +29,7 @@ import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeerSet; import com.alibaba.nacos.naming.core.DistroMapper; import com.alibaba.nacos.naming.core.Service; import com.alibaba.nacos.naming.core.ServiceManager; -import com.alibaba.nacos.naming.misc.SwitchDomain; -import com.alibaba.nacos.naming.misc.SwitchEntry; -import com.alibaba.nacos.naming.misc.SwitchManager; -import com.alibaba.nacos.naming.misc.UtilsAndCommons; +import com.alibaba.nacos.naming.misc.*; import com.alibaba.nacos.naming.pojo.ClusterStateView; import com.alibaba.nacos.naming.push.PushService; import com.alibaba.nacos.naming.web.NeedAuth; @@ -55,7 +52,7 @@ import java.util.List; * @author nkorange */ @RestController -@RequestMapping(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/operator") +@RequestMapping({UtilsAndCommons.NACOS_NAMING_CONTEXT + "/operator", UtilsAndCommons.NACOS_NAMING_CONTEXT + "/ops"}) public class OperatorController { @Autowired @@ -224,6 +221,14 @@ public class OperatorController { return "ok"; } + @RequestMapping(value = "/log", method = RequestMethod.PUT) + public String setLogLevel(HttpServletRequest request) { + String logName = WebUtils.required(request, "logName"); + String logLevel = WebUtils.required(request, "logLevel"); + Loggers.setLogLevel(logName, logLevel); + return "ok"; + } + @RequestMapping(value = "/cluster/states", method = RequestMethod.GET) public Object listStates(HttpServletRequest request) { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java index 74fe9cdbc..c21d5835e 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java @@ -282,27 +282,35 @@ public class ServiceManager implements RecordListener { return; } + boolean changed = false; + List instances = service.allIPs(); for (Instance instance : instances) { - Boolean valid = Boolean.parseBoolean(ipsMap.get(instance.toIPAddr())); + boolean valid = Boolean.parseBoolean(ipsMap.get(instance.toIPAddr())); if (valid != instance.isHealthy()) { + changed = true; instance.setHealthy(valid); - Loggers.EVT_LOG.info("{} {SYNC} IP-{} : {}@{}", + Loggers.EVT_LOG.info("{} {SYNC} IP-{} : {}@{}{}", serviceName, (instance.isHealthy() ? "ENABLED" : "DISABLED"), instance.getIp(), instance.getPort(), instance.getClusterName()); } } - pushService.serviceChanged(service); + if (changed) { + pushService.serviceChanged(service); + } + StringBuilder stringBuilder = new StringBuilder(); List allIps = service.allIPs(); for (Instance instance : allIps) { stringBuilder.append(instance.toIPAddr()).append("_").append(instance.isHealthy()).append(","); } - Loggers.EVT_LOG.info("[IP-UPDATED] namespace: {}, service: {}, ips: {}", - service.getNamespaceId(), service.getName(), stringBuilder.toString()); + if (changed && Loggers.EVT_LOG.isDebugEnabled()) { + Loggers.EVT_LOG.debug("[HEALTH-STATUS-UPDATED] namespace: {}, service: {}, ips: {}", + service.getNamespaceId(), service.getName(), stringBuilder.toString()); + } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckCommon.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckCommon.java index 88489dee4..09525d2e3 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckCommon.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckCommon.java @@ -88,8 +88,8 @@ public class HealthCheckCommon { } Map params = new HashMap<>(10); params.put("result", JSON.toJSONString(list)); - if (Loggers.DEBUG_LOG.isDebugEnabled()) { - Loggers.DEBUG_LOG.debug("[HEALTH-SYNC] server: {}, healthCheckResults: {}", + if (Loggers.SRV_LOG.isDebugEnabled()) { + Loggers.SRV_LOG.debug("[HEALTH-SYNC] server: {}, healthCheckResults: {}", server, JSON.toJSONString(list)); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckTask.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckTask.java index 342e58abd..e15ffb1b3 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckTask.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckTask.java @@ -94,10 +94,13 @@ public class HealthCheckTask implements Runnable { this.setCheckRTLastLast(this.getCheckRTLast()); Cluster cluster = this.getCluster(); - Loggers.CHECK_RT.info("{}:{}@{}->normalized: {}, worst: {}, best: {}, last: {}, diff: {}", - cluster.getService().getName(), cluster.getName(), cluster.getHealthChecker().getType(), - this.getCheckRTNormalized(), this.getCheckRTWorst(), this.getCheckRTBest(), - this.getCheckRTLast(), diff); + + if (Loggers.CHECK_RT.isDebugEnabled()) { + Loggers.CHECK_RT.debug("{}:{}@{}->normalized: {}, worst: {}, best: {}, last: {}, diff: {}", + cluster.getService().getName(), cluster.getName(), cluster.getHealthChecker().getType(), + this.getCheckRTNormalized(), this.getCheckRTWorst(), this.getCheckRTBest(), + this.getCheckRTLast(), diff); + } } } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/Loggers.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/Loggers.java index 01ddd2909..a5178310d 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/Loggers.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/Loggers.java @@ -15,6 +15,7 @@ */ package com.alibaba.nacos.naming.misc; +import ch.qos.logback.classic.Level; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,9 +34,37 @@ public class Loggers { public static final Logger RAFT = LoggerFactory.getLogger("com.alibaba.nacos.naming.raft"); - public static final Logger EPHEMERAL = LoggerFactory.getLogger("com.alibaba.nacos.naming.ephemeral"); + public static final Logger DISTRO = LoggerFactory.getLogger("com.alibaba.nacos.naming.distro"); public static final Logger PERFORMANCE_LOG = LoggerFactory.getLogger("com.alibaba.nacos.naming.performance"); - public static final Logger DEBUG_LOG = LoggerFactory.getLogger("com.alibaba.nacos.naming.debug"); + public static void setLogLevel(String logName, String level) { + + switch (logName) { + case "naming-push": + ((ch.qos.logback.classic.Logger) PUSH).setLevel(Level.valueOf(level)); + break; + case "naming-rt": + ((ch.qos.logback.classic.Logger) CHECK_RT).setLevel(Level.valueOf(level)); + break; + case "naming-server": + ((ch.qos.logback.classic.Logger) SRV_LOG).setLevel(Level.valueOf(level)); + break; + case "naming-event": + ((ch.qos.logback.classic.Logger) EVT_LOG).setLevel(Level.valueOf(level)); + break; + case "naming-raft": + ((ch.qos.logback.classic.Logger) RAFT).setLevel(Level.valueOf(level)); + break; + case "naming-distro": + ((ch.qos.logback.classic.Logger) DISTRO).setLevel(Level.valueOf(level)); + break; + case "naming-performance": + ((ch.qos.logback.classic.Logger) PERFORMANCE_LOG).setLevel(Level.valueOf(level)); + break; + default: + break; + } + + } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java index eb14827a9..59347bb7d 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java @@ -54,7 +54,7 @@ public class NamingProxy { @Override public Object onCompleted(Response response) throws Exception { if (HttpURLConnection.HTTP_OK != response.getStatusCode()) { - Loggers.EPHEMERAL.error("failed to req API: {}, code: {}, msg: {}", + Loggers.DISTRO.error("failed to req API: {}, code: {}, msg: {}", "http://" + server + RunningConfig.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + TIMESTAMP_SYNC_URL, response.getStatusCode(), response.getResponseBody()); @@ -64,13 +64,13 @@ public class NamingProxy { @Override public void onThrowable(Throwable t) { - Loggers.EPHEMERAL.error("failed to req API:" + "http://" + server + Loggers.DISTRO.error("failed to req API:" + "http://" + server + RunningConfig.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + TIMESTAMP_SYNC_URL, t); } }); } catch (Exception e) { - Loggers.EPHEMERAL.warn("NamingProxy", e); + Loggers.DISTRO.warn("NamingProxy", e); } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/ServiceStatusSynchronizer.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/ServiceStatusSynchronizer.java index 8c6ddc8c9..1897a59ab 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/ServiceStatusSynchronizer.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/ServiceStatusSynchronizer.java @@ -79,7 +79,9 @@ public class ServiceStatusSynchronizer implements Synchronizer { String result; try { - Loggers.SRV_LOG.info("[STATUS-SYNCHRONIZE] sync service status from: {}, service: {}", serverIP, key); + if (Loggers.SRV_LOG.isDebugEnabled()) { + Loggers.SRV_LOG.debug("[STATUS-SYNCHRONIZE] sync service status from: {}, service: {}", serverIP, key); + } result = NamingProxy.reqAPI(RunningConfig.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + "/instance/" + "statuses", params, serverIP); } catch (Exception e) { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/monitor/PerformanceLoggerThread.java b/naming/src/main/java/com/alibaba/nacos/naming/monitor/PerformanceLoggerThread.java index 3a36b826f..96d022ede 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/monitor/PerformanceLoggerThread.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/monitor/PerformanceLoggerThread.java @@ -19,7 +19,6 @@ import com.alibaba.nacos.naming.consistency.persistent.raft.RaftCore; import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeer; import com.alibaba.nacos.naming.core.ServiceManager; import com.alibaba.nacos.naming.misc.Loggers; -import com.alibaba.nacos.naming.misc.SwitchDomain; import com.alibaba.nacos.naming.push.PushService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; @@ -42,9 +41,6 @@ public class PerformanceLoggerThread { @Autowired private ServiceManager serviceManager; - @Autowired - private SwitchDomain switchDomain; - @Autowired private PushService pushService; @@ -62,34 +58,15 @@ public class PerformanceLoggerThread { }); private static final long PERIOD = 5 * 60; - private static final long HEALTH_CHECK_PERIOD = 5 * 60; @PostConstruct public void init() { start(); } - private void freshHealthCheckSwitch() { - Loggers.SRV_LOG.info("[HEALTH-CHECK] health check is {}", switchDomain.isHealthCheckEnabled()); - } - - class HealthCheckSwitchTask implements Runnable { - - @Override - public void run() { - try { - freshHealthCheckSwitch(); - } catch (Exception ignore) { - - } - } - } - private void start() { PerformanceLogTask task = new PerformanceLogTask(); executor.scheduleWithFixedDelay(task, 30, PERIOD, TimeUnit.SECONDS); - executor.scheduleWithFixedDelay(new HealthCheckSwitchTask(), 30, HEALTH_CHECK_PERIOD, TimeUnit.SECONDS); - } @Scheduled(cron = "0 0 0 * * ?") diff --git a/naming/src/main/java/com/alibaba/nacos/naming/push/PushService.java b/naming/src/main/java/com/alibaba/nacos/naming/push/PushService.java index 6ef98c834..e2923afab 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/push/PushService.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/push/PushService.java @@ -275,7 +275,9 @@ public class PushService implements ApplicationContextAware, ApplicationListener size += clientConcurrentMap.size(); } - Loggers.PUSH.info("[NACOS-PUSH] clientMap size: {}", size); + if (Loggers.PUSH.isDebugEnabled()) { + Loggers.PUSH.debug("[NACOS-PUSH] clientMap size: {}", size); + } }