Skip to content

Commit

Permalink
[ISSUES alibaba#10029] optimize SearchableProperties building code
Browse files Browse the repository at this point in the history
  • Loading branch information
onewe committed Mar 1, 2023
1 parent b6325fe commit 40b54f1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
*/
class SearchableProperties implements NacosClientProperties {

static final SearchableProperties INSTANCE = new SearchableProperties();

private static final Logger LOGGER = LoggerFactory.getLogger(SearchableProperties.class);

private static final JvmArgsPropertySource JVM_ARGS_PROPERTY_SOURCE = new JvmArgsPropertySource();
Expand Down Expand Up @@ -69,7 +67,7 @@ class SearchableProperties implements NacosClientProperties {
initOrder.set(index, replacedSourceType);
}
} catch (Exception e) {
LOGGER.error("first source type parse error, it will be used default order!", e);
LOGGER.warn("first source type parse error, it will be used default order!", e);
}
}
SEARCH_ORDER = initOrder;
Expand All @@ -83,6 +81,8 @@ class SearchableProperties implements NacosClientProperties {
LOGGER.debug(orderInfo.toString());
}

static final SearchableProperties INSTANCE = new SearchableProperties();

private final List<AbstractPropertySource> propertySources;

private final PropertiesPropertySource propertiesPropertySource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@

package com.alibaba.nacos.client.logging;

import com.alibaba.nacos.client.constant.Constants;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.common.utils.ConvertUtils;
import com.alibaba.nacos.common.utils.StringUtils;

import java.io.File;

/**
* Abstract nacos logging.
*
Expand All @@ -35,16 +32,6 @@ public abstract class AbstractNacosLogging {

private static final String NACOS_LOGGING_DEFAULT_CONFIG_ENABLED_PROPERTY = "nacos.logging.default.config.enabled";

private static final String NACOS_LOGGING_PATH_DIR = "logs";

static {
String loggingPath = NacosClientProperties.PROTOTYPE.getProperty(Constants.SysEnv.JM_LOG_PATH);
if (StringUtils.isBlank(loggingPath)) {
String userHome = NacosClientProperties.PROTOTYPE.getProperty(Constants.SysEnv.USER_HOME);
NacosClientProperties.PROTOTYPE.setProperty(Constants.SysEnv.JM_LOG_PATH, userHome + File.separator + NACOS_LOGGING_PATH_DIR);
}
}

protected String getLocation(String defaultLocation) {
String location = NacosClientProperties.PROTOTYPE.getProperty(NACOS_LOGGING_CONFIG_PROPERTY);
if (StringUtils.isBlank(location)) {
Expand Down
22 changes: 13 additions & 9 deletions client/src/main/resources/nacos-log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
-->

<Configuration status="WARN">
<Properties>
<Property name="userHome" value="${nacosClientProperty:user.home}"/>
<Property name="logPath" value="${nacosClientProperty:JM.LOG.PATH:-${userHome}/logs}"/>
</Properties>
<Appenders>
<RollingFile name="CONFIG_LOG_FILE" fileName="${nacosClientProperty:JM.LOG.PATH}/nacos/config.log"
filePattern="${nacosClientProperty:JM.LOG.PATH}/nacos/config.log.%d{yyyy-MM-dd}.%i">
<RollingFile name="CONFIG_LOG_FILE" fileName="${logPath}/nacos/config.log"
filePattern="${logPath}/nacos/config.log.%d{yyyy-MM-dd}.%i">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
</PatternLayout>
Expand All @@ -29,15 +33,15 @@
</Policies>

<DefaultRolloverStrategy max="${nacosClientProperty:JM.LOG.RETAIN.COUNT:-7}">
<Delete basePath="${nacosClientProperty:JM.LOG.PATH}/nacos" maxDepth="1" testMode="${nacosClientProperty:JM.LOG.RETAIN.DURATION.OFF:-true}">
<Delete basePath="${logPath}/nacos" maxDepth="1" testMode="${nacosClientProperty:JM.LOG.RETAIN.DURATION.OFF:-true}">
<IfFileName glob="config.log.*.*" />
<IfLastModified age="${nacosClientProperty:JM.LOG.RETAIN.DURATION:-P180D}" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>

<RollingFile name="REMOTE_LOG_FILE" fileName="${nacosClientProperty:JM.LOG.PATH}/nacos/remote.log"
filePattern="${nacosClientProperty:JM.LOG.PATH}/nacos/remote.log.%d{yyyy-MM-dd}.%i">
<RollingFile name="REMOTE_LOG_FILE" fileName="${logPath}/nacos/remote.log"
filePattern="${logPath}/nacos/remote.log.%d{yyyy-MM-dd}.%i">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
</PatternLayout>
Expand All @@ -48,15 +52,15 @@
</Policies>

<DefaultRolloverStrategy max="${nacosClientProperty:JM.LOG.RETAIN.COUNT:-7}">
<Delete basePath="${nacosClientProperty:JM.LOG.PATH}/nacos" maxDepth="1" testMode="${nacosClientProperty:JM.LOG.RETAIN.DURATION.OFF:-true}">
<Delete basePath="${logPath}/nacos" maxDepth="1" testMode="${nacosClientProperty:JM.LOG.RETAIN.DURATION.OFF:-true}">
<IfFileName glob="remote.log.*.*" />
<IfLastModified age="${nacosClientProperty:JM.LOG.RETAIN.DURATION:-P180D}" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>

<RollingFile name="NAMING_LOG_FILE" fileName="${nacosClientProperty:JM.LOG.PATH}/nacos/naming.log"
filePattern="${nacosClientProperty:JM.LOG.PATH}/nacos/naming.log.%d{yyyy-MM-dd}.%i">
<RollingFile name="NAMING_LOG_FILE" fileName="${logPath}/nacos/naming.log"
filePattern="${logPath}/nacos/naming.log.%d{yyyy-MM-dd}.%i">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
</PatternLayout>
Expand All @@ -67,7 +71,7 @@
</Policies>

<DefaultRolloverStrategy max="${nacosClientProperty:JM.LOG.RETAIN.COUNT:-7}">
<Delete basePath="${nacosClientProperty:JM.LOG.PATH}/nacos" maxDepth="1" testMode="${nacosClientProperty:JM.LOG.RETAIN.DURATION.OFF:-true}">
<Delete basePath="${logPath}/nacos" maxDepth="1" testMode="${nacosClientProperty:JM.LOG.RETAIN.DURATION.OFF:-true}">
<IfFileName glob="naming.log.*.*" />
<IfLastModified age="${nacosClientProperty:JM.LOG.RETAIN.DURATION:-P180D}" />
</Delete>
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/resources/nacos-logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-->

<configuration debug="false" scan="false" packagingData="true">
<nacosClientProperty scope="context" name="logPath" source="JM.LOG.PATH"/>
<nacosClientProperty scope="context" name="logPath" source="JM.LOG.PATH" defaultValue="${user.home}/logs"/>
<nacosClientProperty scope="context" name="logRetainCount" source="JM.LOG.RETAIN.COUNT" defaultValue="7"/>
<nacosClientProperty scope="context" name="logFileSize" source="JM.LOG.FILE.SIZE" defaultValue="10MB"/>
<nacosClientProperty scope="context" name="nacosConfigLogLevel" source="com.alibaba.nacos.config.log.level" defaultValue="info"/>
Expand Down

0 comments on commit 40b54f1

Please sign in to comment.