• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

sprongboot集成rockrtMq后,修改MQ日志存储路径

开发技术 开发技术 3小时前 1次浏览
一、yml文件中配置相关路径
<configuration scan="true" scanPeriod="10 seconds">
<contextName>logback-test</contextName>

<!--配置日志文件输出路径,下面用${path}占位使用}-->
<property name="path" value="weblogic/webapp/workweixin" />
<property name="APP_NAME" scope="context" source="rocketMqLogs" value="rocketMqLogs"/>
<property name="LOG_DIR" scope="context" source="platform.logging.dir" value="${path}/${APP_NAME}"/>
<property name="LOG_LEVEL" scope="context" source="platform.logging.level" value="INFO"/>
<property name="LOG_POINT_FILE" scope="context" source="platform.logging.dir" value="${path}/point"/>
<property name="LOG_MAXFILESIZE" scope="context" source="platform.logging.maxsize" value="200MB"/>
<property name="LOG_FILEMAXDAY" scope="context" source="platform.logging.maxday" value="600"/>
<property name="ServerIP" scope="context" source="spring.cloud.client.ip-address" value="0.0.0.0"/>
<property name="ServerPort" scope="context" source="server.port" value="0000"/>
<!--0. 日志格式和颜色渲染 -->
<!-- 彩色日志依赖的渲染类 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="pid" converterClass="com.gllic.workweixin.config.ProcessIdConverter" />
<!-- 彩色日志格式 -->
<property name="local_pattern" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%-5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>

<!--文件日志格式-->
<property name="file_pattern" value="%d - %pid - %p - %msg%n"/>

<!--保存所有日志-->
<appender name="fileAllLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>
${file_pattern}
</pattern>
<charset>UTF-8</charset>
</encoder>
<!--滚动输出策略-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--路径-->
<fileNamePattern>${path}/logs.%d.log</fileNamePattern>
<maxHistory>15</maxHistory>
</rollingPolicy>
</appender>
<!--输出日志格式-->
<appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>debug</level>
</filter>
<encoder>
<Pattern>
${local_pattern}
</Pattern>
<!-- 设置字符集 -->
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- rocketmq日志 -->
<appender name="RocketmqClientAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/rocketmq_client.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}/history/rocketmq_client.%d{yyyyMMdd}.%i.log</fileNamePattern>
<maxFileSize>${LOG_MAXFILESIZE}</maxFileSize>
<!--保留时间,单位:天-->
<maxHistory>${LOG_FILEMAXDAY}</maxHistory>
</rollingPolicy>
<encoder charset="UTF-8">
<pattern>%d{yy-MM-dd.HH:mm:ss.SSS} [%-16t] %-5p %-22c{0} %X{ServiceId} - %m%n</pattern>
</encoder>
</appender>
<logger name="RocketmqClient" additivity="false">
<level value="warn"/>
<appender-ref ref="RocketmqClientAppender"/>
</logger>
<!--&lt;!&ndash;只保存info日志&ndash;&gt;-->
<!--<appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
<!--<filter class="ch.qos.logback.classic.filter.LevelFilter">-->
<!--<level>INFO</level>-->
<!--<onMatch>ACCEPT</onMatch>-->
<!--<onMismatch>DENY</onMismatch>-->
<!--</filter>-->
<!--<encoder>-->
<!--<pattern>-->
<!--${file_pattern}-->
<!--</pattern>-->
<!--<charset>UTF-8</charset>-->
<!--</encoder>-->
<!--&lt;!&ndash;滚动输出策略&ndash;&gt;-->
<!--<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
<!--&lt;!&ndash;路径&ndash;&gt;-->
<!--<fileNamePattern>${path}/info.%d.log</fileNamePattern>-->
<!--<maxHistory>15</maxHistory>-->
<!--</rollingPolicy>-->
<!--</appender>-->

<!--&lt;!&ndash;只保存warn日志&ndash;&gt;-->

<!--<appender name="fileWarnLog" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
<!--<filter class="ch.qos.logback.classic.filter.LevelFilter">-->
<!--<level>WARN</level>-->
<!--<onMatch>ACCEPT</onMatch>-->
<!--<onMismatch>DENY</onMismatch>-->
<!--</filter>-->
<!--<encoder>-->
<!--<pattern>-->
<!--${file_pattern}-->
<!--</pattern>-->
<!--<charset>UTF-8</charset>-->
<!--</encoder>-->
<!--&lt;!&ndash;滚动输出策略&ndash;&gt;-->
<!--<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
<!--&lt;!&ndash;路径&ndash;&gt;-->
<!--<fileNamePattern>${path}/warn.%d.log</fileNamePattern>-->
<!--<maxHistory>15</maxHistory>-->
<!--</rollingPolicy>-->
<!--</appender>-->

<!--&lt;!&ndash;只保存error日志&ndash;&gt;-->
<!--<appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
<!--<filter class="ch.qos.logback.classic.filter.ThresholdFilter">-->
<!--<level>ERROR</level>-->
<!--</filter>-->
<!--<encoder>-->
<!--<pattern>-->
<!--${file_pattern}-->
<!--</pattern>-->
<!--<charset>UTF-8</charset>-->
<!--</encoder>-->
<!--&lt;!&ndash;滚动输出策略&ndash;&gt;-->
<!--<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
<!--&lt;!&ndash;路径&ndash;&gt;-->
<!--<fileNamePattern>${path}/error.%d.log</fileNamePattern>-->
<!--<maxHistory>15</maxHistory>-->
<!--</rollingPolicy>-->
<!--</appender>-->

<!--测试环境输出到文件-->
<springProfile name="dtest">
<root level="info">
<appender-ref ref="consoleLog"/>
<appender-ref ref="fileAllLog"/>
<!--<appender-ref ref="fileInfoLog"/>-->
<!--<appender-ref ref="fileWarnLog"/>-->
<!--<appender-ref ref="fileErrorLog"/>-->
</root>
</springProfile>

</configuration>



二、启动方法中配置

@Slf4j
@SpringBootApplication
@EnableBinding(Sink.class)
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
System.setProperty(ClientLogger.CLIENT_LOG_USESLF4J,"true");
String processid = ManagementFactory.getRuntimeMXBean().getName();
log.info("企业微信MQ消息后台 启动成功,进程:{}", processid);
}
}

程序员灯塔
转载请注明原文链接:sprongboot集成rockrtMq后,修改MQ日志存储路径
喜欢 (0)