对于在谷歌搜索后结束的任何人:由于 jmxtrans 中 slf4j、log4j 和 logback 的依赖关系冲突,jmxtrans 中的日志当前已损坏。
https://github.com/jmxtrans/jmxtrans/issues/215
解决此问题的一种方法是将 logback.xml 文件插入到 jmxtrans jar 文件的根目录中:
<property name="logs-folder" value="${catalina.base}/logs"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${jmxtrans.log.dir}/jmxtrans.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>${jmxtrans.log.dir}/jmxtrans_%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 300MB -->
<maxFileSize>300MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date %level [%thread] %logger{36} [%file:%line] %msg%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%date %-5level [%thread] %-36logger{36} [%file:%line][%method] %msg%n</Pattern>
</layout>
</appender>
<logger name="com.googlecode.jmxtrans" level="${jmxtrans.log.level}"/>
<logger name="org.quartz" level="WARN"/>
<root level="DEBUG">
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
</root>
请注意,我在日志中添加了滚动策略(您可以删除它并改用 Linux logrotate 实用程序)。