简体   繁体   English

将FQDN添加到SLF4J / Logback中的日志消息

[英]Add FQDN to log messages in SLF4J/Logback

I am using Logback to feed data into Logstash via a TCP appender . 我正在使用Logback通过TCP附加程序将数据输入Logstash。

The problem I have is that I can get the unqualified hostname (eg myhostname ) of the application creating logs out-of-the-box, but I can't see a way to get the FQDN (eg myhostname.mydomain.com ) to be logged instead. 我遇到的问题是,我可以开箱即用地获取创建日志的应用程序的不合格主机名 (例如myhostname ),但是我看不到将FQDN(例如myhostname.mydomain.com )获取到的方法。改为登录。

I can see here that Logback comes with the HOSTNAME variable already configured in its Context, but I can't expand that to get the fqdn instead... 在这里可以看到Logback附带了已经在其Context中配置的HOSTNAME变量,但是我无法对其进行扩展以获取fqdn。

Edit: What I need is a way, from the logback configuration itself , to get hold og this info. 编辑:我需要的是一种从登录配置本身获取信息的方法。 Unfortunately, I can't modify the code that will emit the log message itself. 不幸的是,我无法修改将发出日志消息本身的代码。

Any idea? 任何想法?

Thanks 谢谢

You can try and resolve your name to IP address or to FQDN. 您可以尝试将名称解析为IP地址或FQDN。 Use InetAddress class and its static method getByName(String name) to try and resolve your name. 使用InetAddress类及其静态方法getByName(String name)尝试解析您的名字。 After that you can retrieve from it IP address or FQDN by method "public String getCanonicalHostName()" 之后,您可以通过方法“ public String getCanonicalHostName()”从其IP地址或FQDN检索

As mentioned in the logback documentation , HOSTNAME is automatically defined as variable within context scope as is available from within the configuration file. 回溯文档中所述,HOSTNAME被自动定义为上下文范围内的变量,可从配置文件中获得。

The fully qualified domain is not defined automatically. 不会自动定义完全限定的域。 However, you could define it on the fly with a custom property definer . 但是,您可以使用自定义属性定义器动态定义它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM