Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With the parameter $PreserveFQDN on the logged-in host is not the full host(FQDN) #1740

Closed
Roarca opened this issue Aug 28, 2023 · 1 comment · Fixed by #2853
Closed

With the parameter $PreserveFQDN on the logged-in host is not the full host(FQDN) #1740

Roarca opened this issue Aug 28, 2023 · 1 comment · Fixed by #2853
Labels
bug Incorrect, unexpected, or unintended behavior of existing code layouts Affects one or more Layout plugins runtime Specific to the runtime environment
Milestone

Comments

@Roarca
Copy link

Roarca commented Aug 28, 2023

Description

When on the client side you activate the $PreserveFQDN property on /etc/rsyslog.conf , the logs do not include the FQDN and only include the host

Configuration

My rsyslog.conf configuration (everything is default except the parameter)

$PreserveFQDN on

The /etc/hosts file

127.0.0.1 host.app.example host

And the log4j2 configuration

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
	<Appenders>
		<Console name="LogToConsole" target="SYSTEM_OUT">
			<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
		</Console>
		<Syslog name="RFC5424" format="RFC5424" host="localhost" port="514" protocol="TCP" appName="app" includeMDC="true" facility="LOCAL0" enterpriseNumber="18060" newLine="true" messageId="app-ID" mdcId="mdc" id="app-MDCID" connectTimeoutMillis="1000" immediateFail="true" reconnectionDelayMillis="5000">
			<LoggerFields>
				<KeyValuePair key="thread" value="%t" />
				<KeyValuePair key="priority" value="%p" />
				<KeyValuePair key="category" value="%c" />
				<KeyValuePair key="exception" value="%ex" />
				<KeyValuePair key="message" value="%m" />
			</LoggerFields>
		</Syslog>
	</Appenders>
	<category name="org.springframework.beans">
		<priority value="info" />
	</category>
	<Loggers>
		<Logger name="foo.example.ErrorService" additivity="false">
			<AppenderRef ref="RFC5424" />
			<AppenderRef ref="LogToConsole" />
		</Logger>
	</Loggers>
</Configuration>

Version: [Log4j version]

2.17.0

Operating system: [OS and version]

SUSE Linux Enterprise Server 12 SP3

JDK: [JDK distribution and version]

OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

Logs

2023-08-24 14:01:49.569 host app[4539] [status] Starting...

Reproduction

Activating the $PreserveFQDN on parameter and having in /etc/hosts an FQDN longer than the normal host should be enough, but ask any questions you may have

@ppkarwasz ppkarwasz added the bug Incorrect, unexpected, or unintended behavior of existing code label Aug 28, 2023
@ppkarwasz
Copy link
Contributor

@Roarca,
Thanks for the report. The bug is easily reproducible if the system call gethostname() returns an unqualified host name.

We use InetAddress#getLocalHost() to retrieve the local hostname, which calls gethostname(), performs a lookup for the fully qualified hostname and ignores the result (cf. source code).

This is why you see just host as hostname.

As a workaround, you can change the hostname of the machine:

hostname host.app.example

It is not the UNIX way, but most services should work without any problems. You can also use uts_namespaces to isolate the hostname of your app from the rest of the system.

@jvz jvz added runtime Specific to the runtime environment layouts Affects one or more Layout plugins labels Oct 15, 2023
@ppkarwasz ppkarwasz added this to the 2.24.0 milestone Aug 16, 2024
ppkarwasz added a commit that referenced this issue Aug 18, 2024
Since RFC5424 specifies that the
[`HOSTNAME`](https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.4)
field should contain the FQDN of the current host,
we add a `useFqdn` configuration attribute to RFC5424
Layout that replaces the usage of `InetAddress.getHostName()`
with `InetAddress.getCanonicalHostName()`.

Closes #1740.
ppkarwasz added a commit that referenced this issue Sep 1, 2024
Since RFC5424 specifies that the
[`HOSTNAME`](https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.4)
field should contain the FQDN of the current host,
we replace replace the usage of `InetAddress.getHostName()`
with `InetAddress.getCanonicalHostName()`.

Closes #1740.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect, unexpected, or unintended behavior of existing code layouts Affects one or more Layout plugins runtime Specific to the runtime environment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants