我想在 java spring 中将多文件 java 的进程写入 1 个文件日志中。这是我的 logback.xml 文件:
<configuration>
<property name="HOME_LOG" value="logs"/>
<appender name="001" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${HOME_LOG}/001/application.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${HOME_LOG}/001.%d{yyyy-MM-dd ss}.%i.log.gz</fileNamePattern>
<!-- each archived file, size max 10MB -->
<maxFileSize>10MB</maxFileSize>
<!-- total size of all archive files, if total size > 20GB, it will delete old archived file -->
<totalSizeCap>10GB</totalSizeCap>
<!-- 60 days to keep -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d %p %c{1.} [%t] %m%n</pattern>
</encoder>
</appender>
<logger name="001" level="INFO">
<appender-ref ref="001"/>
</logger>
现在我想从 2 个 java 文件写入日志:demo1.java 和 demo2.java。这是代码java:
file demo1.java
private final static Logger log001 = LoggerFactory.getLogger("001");
log001.info("I am java 1");
file demo2.java
private final static Logger log001 = LoggerFactory.getLogger("001");
log001.info("I am java 2");
我希望我的日志文件可以显示 2 个文本:“我是 java 1”和“我是 java 2”。现在正在写入覆盖。
慕哥6287543
相关分类