简体   繁体   中英

Is it possible to log the server IP address by using log4j2?

I have log4j2.properties file which is used for the application log. Now by using that properties file I need to print the hostname/ip address to the output log file. I do not want to modify application code(java class) for this.

If you want to print server host name in your web application, then include ${hostName} in your layout pattern.

For log4j2 properties configuration , below pattern should print hostname of the server -

appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} ${hostName} %level [%t] [%c] [%M] [%l] - %msg%n

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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