Ad
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
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>
Ad
Answer
added ${hostName} worked!
fileName="/apps/xyz-${hostName}.log"
Ad
source: stackoverflow.com
Related Questions
- → Upload file with iron-ajax (Google Polymer)
- → Trying to use React/Ajax calls with Spring MVC and Thymeleaf
- → Removing # from URL does not work after deployment - HTTP 404
- → Remove hash (#) from URL in Jhipster (both java and angular 6)
- → Using JavaScript Spring MVC Client Side Validation
- → Spring react - operator =>
- → How to use Thymeleaf th:text in reactJS
- → Having a service called with STOMP which accepts more than one parameter
- → EGit: Issuing a fast-forward pull ~ How to configure fetch for a remote repository in EGit
- → Many-to-Many with extra column (Hibernate 4)
- → Connection to database with JdbcTemplate
- → Spring Boot Security and Auth0 - Cannot disable CSRF
- → Swift UIViewAnimation with spring moves to wrong place then jumps
Ad