Comments (3)
Thanks for bringing this up!
It's very interesting, because according to the JavaDocs this should never happen, rather the method getCanonicalHostName()
should return:
the fully qualified domain name for this IP address, or if the operation is not allowed by the security check, the textual representation of the IP address
Before changing any code, I'd like to understand the cause of this problem. Can you share some additional information about your operating system, java vendor and version and how your systems host name is configured?
from logback-gelf.
Thanks for your reply
Test Code
import java.net.InetAddress;
import java.util.*;
public class Test {
public static void main(String[] args) throws Exception {
InetAddress ia = InetAddress.getLocalHost();
String name = ia.getCanonicalHostName();
System.out.println(name);
String hostname= ia.getHostName();
System.out.println(hostname);
}
}
Dev
uname -a
Darwin gxk.mini 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64
java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
hostname
gxk.mini
ping `hostname` -c 1
PING gxk.mini (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.029 ms
--- gxk.mini ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.029/0.029/0.029/0.000 ms
Prod
uname -a
Linux wp-app-2-51.duitang.cn 4.13.10-1.el7.elrepo.x86_64 #1 SMP Fri Oct 27 09:07:34 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
hostname
wp-app-2-51.duitang.cn
ping `hostname` -c 1
PING wp-app-2-51.duitang.cn (10.1.2.51) 56(84) bytes of data.
64 bytes from 10.1.2.51: icmp_seq=1 ttl=64 time=0.033 ms
--- wp-app-2-51.duitang.cn ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.033/0.033/0.033/0.000 ms
Note
- The Dev env works well. The Prod env get empty.
- the name ip mapping defined in the /etc/hosts
- no outer dns can resolve the hostname.
that's all, thanks, i don't want to dig into temporary.
if you want more info , i will provide.
from logback-gelf.
I've checked the code of java.net.InetAddress#getCanonicalHostName
and I think that the only reason why this method could return an empty string (undocumented!) instead of a hostname or ip address is because of some nameserver misconfiguration or because of a JDK bug. Although, I couldn't find any related bug reports or discussions on the internet about this behavior. In Moocars implementation this is handled (by chance?) because the library is checking if the hostname contains .
and is not an IP address (to detect if it is fully qualified). But that implementation does not support IPv6 and prefers java.net.InetAddress#getHostName()
instead of the ip address that might be returned by java.net.InetAddress#getCanonicalHostName
which might be ambiguous.
I fixed this issue by 187f2f9 and released 2.1.1.
from logback-gelf.
Related Issues (20)
- All newlines in short messages are replaced with whitespaces HOT 10
- GelfHttpAppender does not set Uri HOT 1
- Improve test coverage
- Add the possibility to filter included MDC keys HOT 3
- Add a configurable socket timeout HOT 5
- Macbook GelfUdpAppender garbled HOT 2
- GZIP Compression with GelfUdpAppender HOT 1
- Update logback-classic to 1.2.8 HOT 3
- Logback-classic release 1.2.9
- tcp configuration error HOT 3
- Add ability to log thread ID in addition to thread name HOT 2
- Enable adding multiple static fields via environment variable and/or logback.properties HOT 2
- Mutual TLS fails, HOT 1
- Add another method for adding static field to GelfEncoder HOT 2
- GelfMessage should fail on host = "", shortmessage="" HOT 4
- Add ability to log formatted time HOT 1
- Add use of structured arguments HOT 1
- JSON Encoding Performance HOT 1
- Several minor improvements HOT 1
- Faster MessageIdSupplier with less object allocation, error-prone HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logback-gelf.