Skip to content

Commit

Permalink
Optimize logging statements using placeholder (alibaba#1736)
Browse files Browse the repository at this point in the history
* Optimize logging statements using placeholder to avoid unnecessary concatenation (issue alibaba#1735)
  • Loading branch information
nickChenyx authored Sep 17, 2020
1 parent 510c1d0 commit 2ebf4e8
Show file tree
Hide file tree
Showing 47 changed files with 97 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ private static void initializeApiChangeObserverSpi() {
List<ApiDefinitionChangeObserver> listeners = SpiLoader.loadInstanceList(ApiDefinitionChangeObserver.class);
for (ApiDefinitionChangeObserver e : listeners) {
API_CHANGE_OBSERVERS.put(e.getClass().getCanonicalName(), e);
RecordLog.info("[GatewayApiDefinitionManager] ApiDefinitionChangeObserver added: "
+ e.getClass().getCanonicalName());
RecordLog.info("[GatewayApiDefinitionManager] ApiDefinitionChangeObserver added: {}"
, e.getClass().getCanonicalName());
}
}

Expand Down Expand Up @@ -103,13 +103,13 @@ private static final class ApiDefinitionPropertyListener implements PropertyList
@Override
public void configUpdate(Set<ApiDefinition> set) {
applyApiUpdateInternal(set);
RecordLog.info("[GatewayApiDefinitionManager] Api definition updated: " + API_MAP);
RecordLog.info("[GatewayApiDefinitionManager] Api definition updated: {}", API_MAP);
}

@Override
public void configLoad(Set<ApiDefinition> set) {
applyApiUpdateInternal(set);
RecordLog.info("[GatewayApiDefinitionManager] Api definition loaded: " + API_MAP);
RecordLog.info("[GatewayApiDefinitionManager] Api definition loaded: {}", API_MAP);
}

private static synchronized void applyApiUpdateInternal(Set<ApiDefinition> set) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CommandResponse<String> handle(CommandRequest request) {
return CommandResponse.ofFailure(e, "decode gateway rule data error");
}

RecordLog.info(String.format("[API Server] Receiving rule change (type: gateway rule): %s", data));
RecordLog.info("[API Server] Receiving rule change (type: gateway rule): {}", data);

String result = SUCCESS_MSG;
Set<GatewayFlowRule> flowRules = JSON.parseObject(data, new TypeReference<Set<GatewayFlowRule>>() {
Expand Down Expand Up @@ -93,4 +93,4 @@ public synchronized static void setWritableDataSource(WritableDataSource<Set<Gat

private static final String SUCCESS_MSG = "success";
private static final String WRITE_DS_FAILURE_MSG = "partial success (write data source failed)";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ private static final class GatewayRulePropertyListener implements PropertyListen
@Override
public void configUpdate(Set<GatewayFlowRule> conf) {
applyGatewayRuleInternal(conf);
RecordLog.info("[GatewayRuleManager] Gateway flow rules received: " + GATEWAY_RULE_MAP);
RecordLog.info("[GatewayRuleManager] Gateway flow rules received: {}", GATEWAY_RULE_MAP);
}

@Override
public void configLoad(Set<GatewayFlowRule> conf) {
applyGatewayRuleInternal(conf);
RecordLog.info("[GatewayRuleManager] Gateway flow rules loaded: " + GATEWAY_RULE_MAP);
RecordLog.info("[GatewayRuleManager] Gateway flow rules loaded: {}", GATEWAY_RULE_MAP);
}

private int getIdxInternal(Map<String, Integer> idxMap, String resourceName) {
Expand Down Expand Up @@ -271,7 +271,7 @@ private void applyToConvertedParamMap(Set<ParamFlowRule> paramFlowRules) {
CONVERTED_PARAM_RULE_MAP.clear();
CONVERTED_PARAM_RULE_MAP.putAll(newRuleMap);

RecordLog.info("[GatewayRuleManager] Converted internal param rules: " + CONVERTED_PARAM_RULE_MAP);
RecordLog.info("[GatewayRuleManager] Converted internal param rules: {}", CONVERTED_PARAM_RULE_MAP);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void initNewConnection() {
try {
this.transportClient = new NettyTransportClient(host, port);
this.serverDescriptor = new TokenServerDescriptor(host, port);
RecordLog.info("[DefaultClusterTokenClient] New client created: " + serverDescriptor);
RecordLog.info("[DefaultClusterTokenClient] New client created: {}", serverDescriptor);
} catch (Exception ex) {
RecordLog.warn("[DefaultClusterTokenClient] Failed to initialize new token client", ex);
}
Expand All @@ -97,7 +97,7 @@ private void changeServer(/*@Valid*/ ClusterClientAssignConfig config) {
this.transportClient = new NettyTransportClient(config.getServerHost(), config.getServerPort());
this.serverDescriptor = new TokenServerDescriptor(config.getServerHost(), config.getServerPort());
startClientIfScheduled();
RecordLog.info("[DefaultClusterTokenClient] New client created: " + serverDescriptor);
RecordLog.info("[DefaultClusterTokenClient] New client created: {}", serverDescriptor);
} catch (Exception ex) {
RecordLog.warn("[DefaultClusterTokenClient] Failed to change remote token server", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public void operationComplete(ChannelFuture future) {
} else {
failConnectedTime.set(0);
channel = future.channel();
RecordLog.info(
"[NettyTransportClient] Successfully connect to server <" + host + ":" + port + ">");
RecordLog.info("[NettyTransportClient] Successfully connect to server <{}:{}>", host, port);
}
}
});
Expand All @@ -144,7 +143,7 @@ public void run() {
@Override
public void run() {
if (shouldRetry.get()) {
RecordLog.info("[NettyTransportClient] Reconnecting to server <" + host + ":" + port + ">");
RecordLog.info("[NettyTransportClient] Reconnecting to server <{}:{}>", host, port);
try {
startInternal();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ private static void resolveInstance() {
RecordLog.warn("[ClientEntityCodecProvider] No existing request entity writer, resolve failed");
} else {
requestEntityWriter = writer;
RecordLog.info("[ClientEntityCodecProvider] Request entity writer resolved: " + requestEntityWriter.getClass().getCanonicalName());
RecordLog.info("[ClientEntityCodecProvider] Request entity writer resolved: {}",
requestEntityWriter.getClass().getCanonicalName());
}
ResponseEntityDecoder decoder = SpiLoader.loadFirstInstance(ResponseEntityDecoder.class);
if (decoder == null) {
RecordLog.warn("[ClientEntityCodecProvider] No existing response entity decoder, resolve failed");
} else {
responseEntityDecoder = decoder;
RecordLog.info("[ClientEntityCodecProvider] Response entity decoder resolved: " + responseEntityDecoder.getClass().getCanonicalName());
RecordLog.info("[ClientEntityCodecProvider] Response entity decoder resolved: {}",
responseEntityDecoder.getClass().getCanonicalName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private synchronized void applyConfig(ClusterClientAssignConfig config) {
return;
}

RecordLog.info("[ClusterClientConfigManager] Assign to new target token server: " + config);
RecordLog.info("[ClusterClientConfigManager] Assign to new target token server: {}", config);

updateServerAssignment(config);
}
Expand All @@ -156,11 +156,11 @@ public void configUpdate(ClusterClientConfig config) {
private synchronized void applyConfig(ClusterClientConfig config) {
if (!isValidClientConfig(config)) {
RecordLog.warn(
"[ClusterClientConfigManager] Invalid cluster client config, ignoring: " + config);
"[ClusterClientConfigManager] Invalid cluster client config, ignoring: {}", config);
return;
}

RecordLog.info("[ClusterClientConfigManager] Updating to new client config: " + config);
RecordLog.info("[ClusterClientConfigManager] Updating to new client config: {}", config);

updateClientConfigChange(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public TokenClientHandler(AtomicInteger currentState, Runnable disconnectCallbac
public void channelActive(ChannelHandlerContext ctx) throws Exception {
currentState.set(ClientConstants.CLIENT_STATUS_STARTED);
fireClientPing(ctx);
RecordLog.info("[TokenClientHandler] Client handler active, remote address: " + getRemoteAddress(ctx));
RecordLog.info("[TokenClientHandler] Client handler active, remote address: {}", getRemoteAddress(ctx));
}

@Override
Expand Down Expand Up @@ -90,12 +90,12 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
RecordLog.info("[TokenClientHandler] Client handler inactive, remote address: " + getRemoteAddress(ctx));
RecordLog.info("[TokenClientHandler] Client handler inactive, remote address: {}", getRemoteAddress(ctx));
}

@Override
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
RecordLog.info("[TokenClientHandler] Client channel unregistered, remote address: " + getRemoteAddress(ctx));
RecordLog.info("[TokenClientHandler] Client channel unregistered, remote address: {}", getRemoteAddress(ctx));
currentState.set(ClientConstants.CLIENT_STATUS_OFF);

disconnectCallback.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CommandResponse<String> handle(CommandRequest request) {
}
try {
data = URLDecoder.decode(data, "utf-8");
RecordLog.info("[ModifyClusterClientConfigHandler] Receiving cluster client config: " + data);
RecordLog.info("[ModifyClusterClientConfigHandler] Receiving cluster client config: {}", data);
ClusterClientStateEntity entity = JSON.parseObject(data, ClusterClientStateEntity.class);

ClusterClientConfigManager.applyNewConfig(entity.toClientConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public static Supplier<String> getNamespaceSupplier() {
public static void setNamespaceSupplier(Supplier<String> namespaceSupplier) {
AssertUtil.notNull(namespaceSupplier, "namespaceSupplier cannot be null");
ConfigSupplierRegistry.namespaceSupplier = namespaceSupplier;
RecordLog.info("[ConfigSupplierRegistry] New namespace supplier provided, current supplied: "
+ namespaceSupplier.get());
RecordLog.info("[ConfigSupplierRegistry] New namespace supplier provided, current supplied: {}",
namespaceSupplier.get());
}

private ConfigSupplierRegistry() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void clearToken() {
for (int i = 0; i < executeCount && i < keyList.size(); i++) {
// time out execution exit
if (System.currentTimeMillis() - start > executeDuration) {
RecordLog.info("[RegularExpireStrategy] End the process of expired token detection because of execute time is more than executeDuration:", executeDuration);
RecordLog.info("[RegularExpireStrategy] End the process of expired token detection because of execute time is more than executeDuration: {}", executeDuration);
break;
}
Long key = keyList.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void operationComplete(ChannelFuture future) {
RecordLog.info("[NettyTransportServer] Failed to start token server when retrying", e);
}
} else {
RecordLog.info("[NettyTransportServer] Token server started success at port " + port);
RecordLog.info("[NettyTransportServer] Token server started success at port {}", port);
currentState.compareAndSet(SERVER_STATUS_STARTING, SERVER_STATUS_STARTED);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,16 @@ private static void resolveInstance() {
RecordLog.warn("[ServerEntityCodecProvider] No existing response entity writer, resolve failed");
} else {
responseEntityWriter = writer;
RecordLog.info(
"[ServerEntityCodecProvider] Response entity writer resolved: " + responseEntityWriter.getClass()
.getCanonicalName());
RecordLog.info("[ServerEntityCodecProvider] Response entity writer resolved: {}",
responseEntityWriter.getClass().getCanonicalName());
}
RequestEntityDecoder decoder = SpiLoader.loadFirstInstance(RequestEntityDecoder.class);
if (decoder == null) {
RecordLog.warn("[ServerEntityCodecProvider] No existing request entity decoder, resolve failed");
} else {
requestEntityDecoder = decoder;
RecordLog.info(
"[ServerEntityCodecProvider] Request entity decoder resolved: " + requestEntityDecoder.getClass()
.getCanonicalName());
RecordLog.info("[ServerEntityCodecProvider] Request entity decoder resolved: {}",
requestEntityDecoder.getClass().getCanonicalName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public CommandResponse<String> handle(CommandRequest request) {
data = URLDecoder.decode(data, "utf-8");

if (StringUtil.isEmpty(namespace)) {
RecordLog.info("[ModifyClusterServerFlowConfigHandler] Receiving cluster server global flow config: " + data);
RecordLog.info("[ModifyClusterServerFlowConfigHandler] Receiving cluster server global flow config: {}", data);
ServerFlowConfig config = JSON.parseObject(data, ServerFlowConfig.class);
if (!ClusterServerConfigManager.isValidFlowConfig(config)) {
CommandResponse.ofFailure(new IllegalArgumentException("Bad flow config"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CommandResponse<String> handle(CommandRequest request) {
}
try {
data = URLDecoder.decode(data, "utf-8");
RecordLog.info("[ModifyServerNamespaceSetHandler] Receiving cluster server namespace set: " + data);
RecordLog.info("[ModifyServerNamespaceSetHandler] Receiving cluster server namespace set: {}", data);
Set<String> set = JSON.parseObject(data, new TypeReference<Set<String>>() {});
ClusterServerConfigManager.loadServerNamespaceSet(set);
return CommandResponse.ofSuccess("success");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private static void applyNamespaceSetChange(Set<String> newSet) {
if (newSet == null) {
return;
}
RecordLog.info("[ClusterServerConfigManager] Server namespace set will be update to: " + newSet);
RecordLog.info("[ClusterServerConfigManager] Server namespace set will be update to: {}", newSet);
if (newSet.isEmpty()) {
ClusterServerConfigManager.namespaceSet = Collections.singleton(ServerConstants.DEFAULT_NAMESPACE);
return;
Expand Down Expand Up @@ -276,10 +276,10 @@ public void configUpdate(ServerTransportConfig config) {
private synchronized void applyConfig(ServerTransportConfig config) {
if (!isValidTransportConfig(config)) {
RecordLog.warn(
"[ClusterServerConfigManager] Invalid cluster server transport config, ignoring: " + config);
"[ClusterServerConfigManager] Invalid cluster server transport config, ignoring: {}", config);
return;
}
RecordLog.info("[ClusterServerConfigManager] Updating new server transport config: " + config);
RecordLog.info("[ClusterServerConfigManager] Updating new server transport config: {}", config);
if (config.getIdleSeconds() != idleSeconds) {
idleSeconds = config.getIdleSeconds();
}
Expand Down Expand Up @@ -315,10 +315,10 @@ public void configLoad(ServerFlowConfig config) {
private synchronized void applyGlobalFlowConfig(ServerFlowConfig config) {
if (!isValidFlowConfig(config)) {
RecordLog.warn(
"[ClusterServerConfigManager] Invalid cluster server global flow config, ignoring: " + config);
"[ClusterServerConfigManager] Invalid cluster server global flow config, ignoring: {}", config);
return;
}
RecordLog.info("[ClusterServerConfigManager] Updating new server global flow config: " + config);
RecordLog.info("[ClusterServerConfigManager] Updating new server global flow config: {}", config);
if (config.getExceedCount() != exceedCount) {
exceedCount = config.getExceedCount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ public void run() {
List<Connection> connections = connectionPool.listAllConnection();
for (Connection conn : connections) {
if ((now - conn.getLastReadTime()) > idleTimeMillis) {
RecordLog.info(
String.format("[ScanIdleConnectionTask] The connection <%s:%d> has been idle for <%d>s. "
+ "It will be closed now.", conn.getRemoteIP(), conn.getRemotePort(), idleSeconds)
);
RecordLog.info("[ScanIdleConnectionTask] The connection <{}:{}> has been idle for <{}>s. It will be closed now.",
conn.getRemoteIP(), conn.getRemotePort(), idleSeconds);
conn.close();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public synchronized void configUpdate(List<EnvoyRlsRule> conf) {

RULE_MAP.clear();
RULE_MAP.putAll(ruleMap);
RecordLog.info("[EnvoyRlsRuleManager] Envoy RLS rules loaded: " + flowRules);
RecordLog.info("[EnvoyRlsRuleManager] Envoy RLS rules loaded: {}", flowRules);

// Use the "default" namespace.
ClusterFlowRuleManager.loadRules(ServerConstants.DEFAULT_NAMESPACE, flowRules);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ private static void resolveTokenClientInstance() {
"[TokenClientProvider] No existing cluster token client, cluster client mode will not be activated");
} else {
client = resolvedClient;
RecordLog.info(
"[TokenClientProvider] Cluster token client resolved: " + client.getClass().getCanonicalName());
RecordLog.info("[TokenClientProvider] Cluster token client resolved: {}",
client.getClass().getCanonicalName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ private static void resolveInstance() {
RecordLog.warn("[EmbeddedClusterTokenServerProvider] No existing cluster token server, cluster server mode will not be activated");
} else {
server = s;
RecordLog.info("[EmbeddedClusterTokenServerProvider] Cluster token server resolved: " + server.getClass().getCanonicalName());
RecordLog.info("[EmbeddedClusterTokenServerProvider] Cluster token server resolved: {}",
server.getClass().getCanonicalName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public final class SentinelConfig {
loadProps();
resolveAppName();
resolveAppType();
RecordLog.info("[SentinelConfig] Application type resolved: " + appType);
RecordLog.info("[SentinelConfig] Application type resolved: {}", appType);
} catch (Throwable ex) {
RecordLog.warn("[SentinelConfig] Failed to initialize", ex);
ex.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static void load() {

Properties p = ConfigUtil.loadProperties(fileName);
if (p != null && !p.isEmpty()) {
RecordLog.info("[SentinelConfigLoader] Loading Sentinel config from " + fileName);
RecordLog.info("[SentinelConfigLoader] Loading Sentinel config from {}", fileName);
properties.putAll(p);
}

Expand Down
Loading

0 comments on commit 2ebf4e8

Please sign in to comment.