Hostname undefined in Logback / SLF4J in a production environment

I use Logback / SLF4J for logging, and it works like a charm on my Mac development machine.

I have the following template used for the mailing subject:

<subject>[ERROR] ${HOSTNAME} : %msg</subject> 

When starting the service on my Mac, I get this question:

 macbook-pro.localhost : Error message 

When I start the service on VBS Debian (Lenny), I get the following email object

 HOSTNAME_IS_UNDEFIENED : Error message 

Entering hostname on the command line for Mac and Debian creates the following:

 mac: macbook-pro.localhost debian: s1.myservice.com 

I would like to see s1.myservice.com in the subject line.

+6
source share
1 answer

Logback gets a HOSTNAME value with InetAddress.getLocalHost (). getHostName () . Check what the following code looks like on your server:

 import java.net.*; final InetAddress localHost = InetAddress.getLocalHost(); System.out.println("hostAddress: " + localHost.getHostAddress()); System.out.println("hostName: " + localHost.getHostName()); 
+4
source

Source: https://habr.com/ru/post/892498/


All Articles