Fix missing node id prefix in startup logs (#29534)

When `node.name` is not set, some log traces at startup time does not
show the node id.
This commit is contained in:
Tanguy Leroux 2018-04-19 09:40:25 +02:00 committed by GitHub
parent 8afa7c174f
commit e2d770d9b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 3 deletions

View File

@ -258,7 +258,6 @@ public class Node implements Closeable {
// use temp logger just to say we are starting. we can't use it later on because the node name might not be set // use temp logger just to say we are starting. we can't use it later on because the node name might not be set
Logger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(environment.settings())); Logger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(environment.settings()));
logger.info("initializing ..."); logger.info("initializing ...");
} }
try { try {
Settings tmpSettings = Settings.builder().put(environment.settings()) Settings tmpSettings = Settings.builder().put(environment.settings())
@ -272,13 +271,13 @@ public class Node implements Closeable {
throw new IllegalStateException("Failed to create node environment", ex); throw new IllegalStateException("Failed to create node environment", ex);
} }
final boolean hadPredefinedNodeName = NODE_NAME_SETTING.exists(tmpSettings); final boolean hadPredefinedNodeName = NODE_NAME_SETTING.exists(tmpSettings);
Logger logger = Loggers.getLogger(Node.class, tmpSettings);
final String nodeId = nodeEnvironment.nodeId(); final String nodeId = nodeEnvironment.nodeId();
tmpSettings = addNodeNameIfNeeded(tmpSettings, nodeId); tmpSettings = addNodeNameIfNeeded(tmpSettings, nodeId);
final Logger logger = Loggers.getLogger(Node.class, tmpSettings);
// this must be captured after the node name is possibly added to the settings // this must be captured after the node name is possibly added to the settings
final String nodeName = NODE_NAME_SETTING.get(tmpSettings); final String nodeName = NODE_NAME_SETTING.get(tmpSettings);
if (hadPredefinedNodeName == false) { if (hadPredefinedNodeName == false) {
logger.info("node name [{}] derived from node ID [{}]; set [{}] to override", nodeName, nodeId, NODE_NAME_SETTING.getKey()); logger.info("node name derived from node ID [{}]; set [{}] to override", nodeId, NODE_NAME_SETTING.getKey());
} else { } else {
logger.info("node name [{}], node ID [{}]", nodeName, nodeId); logger.info("node name [{}], node ID [{}]", nodeName, nodeId);
} }