log4j创建的文件中的主机名 [英] hostname in file created by log4j

查看:547
本文介绍了log4j创建的文件中的主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Linux计算机(RHEL 5.4)上使用Java 1.4.2.

I'm using java 1.4.2 on Linux machine (RHEL 5.4).

我们的应用程序使用log4j进行日志记录.我希望某些追加程序将创建文件名中包含主机名的文件.主机名不应进行硬编码,而应使用类似于的系统属性(请参阅$ {log4j.minutes}).

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.

这意味着我需要从命令行(-D标志)的代码中添加主机名作为系统属性.

This means I need to add hostname as system property from code of from command line (-D flag).

我想念什么吗?

推荐答案

否.系统属性中没有默认主机名.另外,一台计算机可能有多个网卡,每个网卡可能分配了多个IP号,每个IP号可能都有自己的名称,因此默认主机名"可能是多个候选者.

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.

提取完所需的主机名后,请研究如何将其保存在log4j MDC中(这是一种伪装的Map,因此您可以在配置中的日志记录字符串中进行引用).

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).

这篇关于log4j创建的文件中的主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆