0

I want to append hostname and date to the log file name.So log file Name should be like app_hostname.date.log. Note: I need to do this configuration without using any java code. Is that possible?

Currently I am using log4j.properties file to accomplish this where I made the following configuration:

log4j.appender.file=org.apache.log4j.RollingFileAppender

log4j.appender.file.File=${catalina.base}/logs/appLogs_${hostName}.log
log4j.appender.file.MaxFileSize=1MB

log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%t] %-5p %c %x - %m%n

Now the problem is I expect the name of the file to be 'appLogs_localhost.log' but it is actually coming like 'appLogs_.log'. Moreover I want to append the date also. Thanks in advance.

Vineeta
  • 73
  • 5
  • Possible duplicate of [How to append hostname to log file in log4j.xml](https://stackoverflow.com/questions/36170962/how-to-append-hostname-to-log-file-in-log4j-xml) – mikeb May 07 '19 at 14:42
  • @mikeb The solution provided previously is applicable for a web application, but I am using standalone application. – Vineeta May 07 '19 at 18:19
  • Actually, if you look at the accepted answer, it's both `If your application is web-application` <- The part before that works for non-webapps too – mikeb May 07 '19 at 19:04

0 Answers0