Skip to content

Commit 3799c16

Browse files
committed
feat(config):optimize logs for dynamic loading configuration
1 parent 5959a1b commit 3799c16

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

framework/src/main/java/org/tron/core/config/args/DynamicArgs.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ public void start() {
4646
confFile = parameter.getShellConfFileName();
4747
} else {
4848
confFile = Constant.TESTNET_CONF;
49-
//
5049
//logger.warn("Configuration path is required!");
5150
//return;
5251
}
5352

5453
File confDir = new File(confFile);
54+
if (!confDir.exists()) {
55+
logger.warn("Configuration path is required! No such file {}", confFile);
56+
return;
57+
}
5558
confFileName = confDir.getName();
5659
if (confFile.contains(File.separator)) {
5760
path = FileSystems.getDefault().getPath(confDir.getPath()).getParent();
@@ -60,10 +63,10 @@ public void start() {
6063
path = FileSystems.getDefault().getPath(directory.getAbsolutePath());
6164
}
6265

63-
logger.info("confDirString = {}", confDir);
66+
logger.debug("confDirString = {}", confDir);
6467
watchService = FileSystems.getDefault().newWatchService();
6568
path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
66-
logger.info("watch path : {}", path.toString());
69+
logger.debug("watch path : {}", path.toString());
6770
} catch (Exception e) {
6871
logger.error("Exception caught when register the watch key", e.getCause());
6972
return;
@@ -77,27 +80,28 @@ public void start() {
7780
final Path changed = (Path)event.context();
7881
if (changed.endsWith(confFileName)) {
7982
reload();
80-
logger.info("Config was modify and we reload it");
83+
logger.info("The configuration was modified and we reloaded it");
8184
}
8285
changeCount++;
8386
}
84-
logger.info("change count : {}", changeCount);
87+
logger.debug("change count : {}", changeCount);
8588

8689
boolean valid = wk.reset();
8790
if (!valid) {
8891
path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
8992
}
9093
} catch (InterruptedException e) {
91-
logger.warn("");
94+
logger.warn("WatchService was interrupted");
9295
break;
9396
} catch (IOException e) {
97+
logger.error("Exception caught when register the watch key", e.getCause());
9498
break;
9599
}
96100
}
97101
}
98102

99103
public void reload() {
100-
logger.info("reloading ... ");
104+
logger.debug("Reloading ... ");
101105
Config config = Configuration.getByFileName(parameter.getShellConfFileName(),
102106
Constant.TESTNET_CONF);
103107

@@ -116,7 +120,6 @@ private void updateActiveNodes(Config config) {
116120
Args.getInetSocketAddress(config, Constant.NODE_ACTIVE);
117121
parameter.setActiveNodes(newActiveNodes);
118122
parameter.getActiveNodes().forEach(n -> {
119-
logger.info("active node : {}", n.toString());
120123
if (!lastActiveNodes.contains(n)) {
121124
TronNetService.getP2pConfig().getActiveNodes().add(n);
122125
if (!TronNetService.getP2pConfig().getTrustNodes().contains(n.getAddress())) {
@@ -131,6 +134,8 @@ private void updateActiveNodes(Config config) {
131134
TronNetService.getP2pConfig().getTrustNodes().remove(ln.getAddress());
132135
}
133136
});
137+
logger.debug("p2p active nodes : {}",
138+
TronNetService.getP2pConfig().getActiveNodes().toString());
134139
}
135140

136141
private void updateTrustNodes(Config config) {
@@ -142,7 +147,6 @@ private void updateTrustNodes(Config config) {
142147
List<InetAddress> newPassiveNodes = Args.getInetAddress(config, Constant.NODE_PASSIVE);
143148
parameter.setPassiveNodes(newPassiveNodes);
144149
parameter.getPassiveNodes().forEach(n -> {
145-
logger.info("passive node : {}", n.toString());
146150
if (!lastPassiveNodes.contains(n)
147151
|| !TronNetService.getP2pConfig().getTrustNodes().contains(n)) {
148152
TronNetService.getP2pConfig().getTrustNodes().add(n);
@@ -154,6 +158,7 @@ private void updateTrustNodes(Config config) {
154158
TronNetService.getP2pConfig().getTrustNodes().remove(ln);
155159
}
156160
});
161+
logger.debug("p2p trust nodes : {}", TronNetService.getP2pConfig().getTrustNodes().toString());
157162
}
158163

159164
public void close() {

0 commit comments

Comments
 (0)