I’m using java 1.4.2 on Linux machine (RHEL 5.4).
Our application uses log4j for logging. I want that some appender will create files containing hostname in file name. Hostname should not be hardocoded, but rather use system properties similar to here (see ${log4j.minutes}).
So the question is if there’s hostname in system properties.
According to here, there’s no default hostname property.
This means I need to add hostname as system property from code of from command line (-D flag).
Do I miss something?
No. There is no default hostname in the system properties. Also a computer may have multiple netcards, and each netcard may have several IP-numbers allocated and each IP-number may have its own name, so there might be several candidates for what the “default hostname” might be.
When you have extracted the hostname you like, then look into how you can save it in the log4j MDC – which is a Map in disguise – so you can refer to in your logging string in your configuration).