I have my log4j2.xml in which I need to add the hostname to the log file for the file Appender.
I have the following log4j2.xml-
<Configuration status="WARN" monitorInterval="30">
<Properties>
<Property name="LOG_PATTERN">%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %p %m%n</Property>
</Properties>
<Appenders>
<!-- Console Appender -->
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${LOG_PATTERN}"/>
</Console>
<!-- File Appenders on need basis -->
<RollingFile name="FileAppender" fileName="/apps/logs/app-${hostname}.log"
filePattern="/apps/logs/app-%server%-%d{yyyy-MM-dd}-%i.log">
<LevelRangeFilter minLevel="DEBUG" maxLevel="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout>
<Pattern>%d{MM/dd HH:mm:ss,SSS} [%X{jobId}] [%t] %-5p %c{1}.%M:%L %m%n</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10MB" />
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
</Appenders>
</Configuration>
CodePudding user response:
added ${hostName} worked!
fileName="/apps/xyz-${hostName}.log"