Reputation: 1076
I have a server that I developed in Java around intellij. I created a number of different configurations (node1, node2, etc.), each representing another server and another port, and then via spring boot I run them all together.
The problem is that the logs of all the servers write to the same slf4j log file, and according to the requirements of my team leader, I need each server to write logs to a separate file.
Here is the definition in the logback.xml file of the error printing file:
<property name="LOGS_PATH" value="./logs" />
<appender name="ERROR_LOG_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<file>${LOGS_PATH}/fullNode_error.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<Pattern>
%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread][%-5level][%logger{0}] %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGS_PATH}/archived/fullNode_error.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
What am I doing wrong?
Upvotes: 1
Views: 891
Reputation: 11267
You can do this:
<file>${LOGS_PATH}/node-${env.NODE_NAME}_error.log</file>
That will take the NODE_NAME variable from the environment and use it in the filename.
Set NODE_NAME
when you start your app instance and off you go.
You can also use:
<file>${LOGS_PATH}/node-${NODE_NAME}_error.log</file>
and when you run your app, do java -DNODE_NAME=node1 ...
when you start.
Upvotes: 2