Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hostname is undefined in Logback/SLF4J in production environment

I'm using Logback/SLF4J to do logging, and it works like a charm on my Mac development machine.

I have the following pattern used for mail appender subject:

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

When running the service on my Mac, I receive a subject like this:

macbook-pro.localhost : Error message

When I run the service on a Debian (Lenny) VPS, I get the following email subject

HOSTNAME_IS_UNDEFIENED : Error message

Typing hostname in command line for both Mac and Debian machine produces the following:

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

I'd like to see the s1.myservice.com in email subject.

like image 774
Up. Avatar asked Jul 11 '11 14:07

Up.


1 Answers

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

import java.net.*;

final InetAddress localHost = InetAddress.getLocalHost();
System.out.println("hostAddress: " + localHost.getHostAddress());
System.out.println("hostName: " + localHost.getHostName());
like image 77
palacsint Avatar answered Nov 01 '22 08:11

palacsint