mirror of
https://gitee.com/shikong-sk/springcloud-study
synced 2024-11-09 01:51:19 +08:00
日志调整
This commit is contained in:
parent
9b175c581e
commit
7d5859fa4b
53
common/src/main/resources/logback.xml
Normal file
53
common/src/main/resources/logback.xml
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
|
||||
<contextName>logback</contextName>
|
||||
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
|
||||
<!--<property name="log.path" value="./log/business_Log" />-->
|
||||
|
||||
<!--输出到控制台-->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">-->
|
||||
<!-- <level>INFO</level>-->
|
||||
<!-- </filter>-->
|
||||
<!-- <withJansi>true</withJansi>-->
|
||||
<encoder>
|
||||
<!--<pattern>%d %p (%file:%line\)- %m%n</pattern>-->
|
||||
<!--格式化输出:%d:表示日期 %thread:表示线程名 %-5level:级别从左显示5个字符宽度 %msg:日志消息 %n:是换行符-->
|
||||
<pattern>%red(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %yellow(at %class.%method) (%file:%line\) - %cyan(%msg%n)</pattern>
|
||||
<!--<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %magenta(%-5level) %green([%-50.50class]) >>> %cyan(%msg) %n</pattern>-->
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!--<!–输出到文件–>-->
|
||||
<!--<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
|
||||
<!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">-->
|
||||
<!-- <level>INFO</level>-->
|
||||
<!-- </filter>-->
|
||||
<!-- <file>${log.path}/logback.log</file>-->
|
||||
<!-- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
|
||||
<!-- <fileNamePattern>${log.path}/logback-%d{yyyy-MM-dd-HH-mm}.log</fileNamePattern>-->
|
||||
<!-- <maxHistory>365</maxHistory>-->
|
||||
<!-- <!– <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">–>-->
|
||||
<!-- <!– <maxFileSize>100kB</maxFileSize>–>-->
|
||||
<!-- <!– </timeBasedFileNamingAndTriggeringPolicy>–>-->
|
||||
<!-- </rollingPolicy>-->
|
||||
<!-- <encoder>-->
|
||||
<!-- <!–格式化输出:%d:表示日期 %thread:表示线程名 %-5level:级别从左显示5个字符宽度 %msg:日志消息 %n:是换行符–>-->
|
||||
<!-- <pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>-->
|
||||
<!-- <charset>UTF-8</charset>-->
|
||||
<!-- </encoder>-->
|
||||
<!--</appender>-->
|
||||
|
||||
<!-- 如果appender里没有限定日志级别,那么root可以统一设置,如果没有配置那么控制台和文件不会输出任何日志,这里root的level不做限制-->
|
||||
<root level="INFO">
|
||||
<!-- 允许控制台输出-->
|
||||
<appender-ref ref="console" />
|
||||
<!--<!– 允许文件输出–>-->
|
||||
<!--<appender-ref ref="file" />-->
|
||||
</root>
|
||||
|
||||
<logger name="cn.skcks.study.springcloud.kafka.producer.controller" level="DEBUG" />
|
||||
</configuration>
|
@ -2,14 +2,14 @@ package cn.skcks.study.springcloud.kafka.producer.controller;
|
||||
|
||||
import cn.skcks.study.springcloud.kafka.common.model.dto.Message;
|
||||
import cn.skcks.study.springcloud.utils.JsonUtils;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
public class SimpleController {
|
||||
@ -17,16 +17,15 @@ public class SimpleController {
|
||||
final static String TOPIC_NAME = "test";
|
||||
|
||||
@GetMapping("/api/v2/{num}")
|
||||
public void sendMessage1(@PathVariable("num") String num) throws JsonProcessingException {
|
||||
public void sendMessage1(@PathVariable("num") String num) {
|
||||
|
||||
Message message = new Message();
|
||||
message.setData("这是一个消息,num="+num);
|
||||
|
||||
kafkaTemplate.send(TOPIC_NAME,num, JsonUtils.toJson(message)).addCallback(success->{
|
||||
System.out.println("发送成功");
|
||||
|
||||
log.debug("消息 {} 发送成功",message);
|
||||
},failure->{
|
||||
System.out.println("发送消息失败:"+failure.getMessage());
|
||||
log.info("发送消息失败 {}",failure.getMessage());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user