[
https://issues.apache.org/jira/browse/LOG4J2-3436?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17507396#comment-17507396
]
Piotr Karwasz commented on LOG4J2-3436:
---------------------------------------
Hi [~ragini],
Thanks for the additional info. Log4j uses a simple wrapper around
[InetAddress#getLocalHost()|https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/InetAddress.html#getLocalHost()]
to retrieve your hostname. Basically this is equivalent to a call to {{uname
-n}} with a twist: the name must be resolvable. You can check it with:
{noformat}
getent hosts rag101ga
{noformat}
My guess is that resolution of {{rag101ga}} fails on your system and Log4j
falls back to a reverse lookup of all your IP addresses (except the loopback
addresses). One of them must give {{localhost.localdomain}} as an answer.
You can work around this problem by adding to {{/etc/hosts}} an entry like
{noformat}
127.0.1.1 rag101ga.example.com rag101ga
{noformat}
PS: I think the fallback mechanism is incomplete. While trying to reproduce
your symptoms I got a literal IP address as hostname.
> Log4j 2 syslogAppender prints localhost.localdomain instead of actual hostname
> ------------------------------------------------------------------------------
>
> Key: LOG4J2-3436
> URL: https://issues.apache.org/jira/browse/LOG4J2-3436
> Project: Log4j 2
> Issue Type: Bug
> Components: Appenders, Log4j 1.2 bridge
> Environment: Using log4j 2 bridge API: snapshot version of 2.17.3
> log4j-1.2-api-2.17.3.jar
> Reporter: Ragini Gawande
> Assignee: Piotr Karwasz
> Priority: Blocker
>
> We are trying to use syslogAppender for our logging but in the logs its
> prints localhost.localdomain instead of actual hostname
> <13>Mar 14 22:33:41 *localhost.localdomain* Main[6133] +05:30 2022 572 1
> com.test.common.logging.Test | FINE#com.test.common.logging.Level - Can
> print FINE
> <13>Mar 14 22:33:41 *localhost.localdomain* Main[6133] +05:30 2022 572 1
> com.test.common.logging.Test | INFO#com.test.common.logging.Level - Can
> print Info
>
> Here we are using snapshot version of log4j 2.17.3
> This issue was not seen when using log4j 2.17.1
>
> Additional info:
> JDK 1.8
> -Dlog4j1.compatibility=true
--
This message was sent by Atlassian Jira
(v8.20.1#820001)