Suppress forbiddenAPI in logger when using localhost
This commit is contained in:
parent
1e511eda28
commit
60f273c891
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.common.logging;
|
package org.elasticsearch.common.logging;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import org.apache.lucene.util.SuppressForbidden;
|
||||||
import org.elasticsearch.common.Classes;
|
import org.elasticsearch.common.Classes;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
|
@ -74,20 +75,27 @@ public class Loggers {
|
||||||
return getLogger(buildClassLoggerName(clazz), settings, prefixes);
|
return getLogger(buildClassLoggerName(clazz), settings, prefixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressForbidden(reason = "using localhost for logging on which host it is is fine")
|
||||||
|
private static InetAddress getHostAddress() {
|
||||||
|
try {
|
||||||
|
return InetAddress.getLocalHost();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static ESLogger getLogger(String loggerName, Settings settings, String... prefixes) {
|
public static ESLogger getLogger(String loggerName, Settings settings, String... prefixes) {
|
||||||
List<String> prefixesList = newArrayList();
|
List<String> prefixesList = newArrayList();
|
||||||
if (settings.getAsBoolean("logger.logHostAddress", false)) {
|
if (settings.getAsBoolean("logger.logHostAddress", false)) {
|
||||||
try {
|
final InetAddress addr = getHostAddress();
|
||||||
prefixesList.add(InetAddress.getLocalHost().getHostAddress());
|
if (addr != null) {
|
||||||
} catch (UnknownHostException e) {
|
prefixesList.add(addr.getHostAddress());
|
||||||
// ignore
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (settings.getAsBoolean("logger.logHostName", false)) {
|
if (settings.getAsBoolean("logger.logHostName", false)) {
|
||||||
try {
|
final InetAddress addr = getHostAddress();
|
||||||
prefixesList.add(InetAddress.getLocalHost().getHostName());
|
if (addr != null) {
|
||||||
} catch (UnknownHostException e) {
|
prefixesList.add(addr.getHostName());
|
||||||
// ignore
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String name = settings.get("name");
|
String name = settings.get("name");
|
||||||
|
|
Loading…
Reference in New Issue