如何在 log4j2.xml 中为我的日志文件添加主机名?我正在开发 spring 3.0.5,需要将 log4j 迁移到 log4j2
How to add hostname for my log file in log4j2.xml ? I am working on spring 3.0.5 and need to migrate log4j to log4j2
我有我的 log4j2.xml,我需要在其中将主机名添加到文件 Appender 的日志文件中。
我有以下 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>
添加 ${hostName} 成功了!
fileName="/apps/xyz-${hostName}.log"
我有我的 log4j2.xml,我需要在其中将主机名添加到文件 Appender 的日志文件中。
我有以下 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>
添加 ${hostName} 成功了!
fileName="/apps/xyz-${hostName}.log"