first commit
This commit is contained in:
68
l-im-master/l-im/im-message-store/pom.xml
Normal file
68
l-im-master/l-im/im-message-store/pom.xml
Normal file
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>im-system</artifactId>
|
||||
<groupId>com.lld</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>im-message-store</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- rabbitmq -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--MySQL JDBC驱动 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--MySQL -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- mybatis plus -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.jeffreyning</groupId>
|
||||
<artifactId>mybatisplus-plus</artifactId>
|
||||
<version>1.5.1-RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- common -->
|
||||
<dependency>
|
||||
<groupId>com.lld</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.lld.message;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.lld.message.dao.mapper")
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.lld.message.config;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author: Chackylee
|
||||
* @description:
|
||||
**/
|
||||
@Configuration
|
||||
public class BeanConfig {
|
||||
|
||||
/**
|
||||
* 分页插件
|
||||
*/
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
return new PaginationInterceptor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EasySqlInjector easySqlInjector () {
|
||||
return new EasySqlInjector();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.lld.message.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
|
||||
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
||||
import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EasySqlInjector extends DefaultSqlInjector {
|
||||
@Override
|
||||
public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
|
||||
List<AbstractMethod> methodList = super.getMethodList(mapperClass);
|
||||
methodList.add(new InsertBatchSomeColumn()); // 添加InsertBatchSomeColumn方法
|
||||
return methodList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.lld.message.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: Chackylee
|
||||
* @description:
|
||||
**/
|
||||
@Data
|
||||
@TableName("im_group_message_history")
|
||||
public class ImGroupMessageHistoryEntity {
|
||||
|
||||
private Integer appId;
|
||||
|
||||
private String fromId;
|
||||
|
||||
private String groupId;
|
||||
|
||||
/** messageBodyId*/
|
||||
private Long messageKey;
|
||||
/** 序列号*/
|
||||
private Long sequence;
|
||||
|
||||
private String messageRandom;
|
||||
|
||||
private Long messageTime;
|
||||
|
||||
private Long createTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.lld.message.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: Chackylee
|
||||
* @description:
|
||||
**/
|
||||
@Data
|
||||
@TableName("im_message_body")
|
||||
public class ImMessageBodyEntity {
|
||||
|
||||
private Integer appId;
|
||||
|
||||
/** messageBodyId*/
|
||||
private Long messageKey;
|
||||
|
||||
/** messageBody*/
|
||||
private String messageBody;
|
||||
|
||||
private String securityKey;
|
||||
|
||||
private Long messageTime;
|
||||
|
||||
private Long createTime;
|
||||
|
||||
private String extra;
|
||||
|
||||
private Integer delFlag;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.lld.message.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: Chackylee
|
||||
* @description:
|
||||
**/
|
||||
@Data
|
||||
@TableName("im_message_history")
|
||||
public class ImMessageHistoryEntity {
|
||||
|
||||
private Integer appId;
|
||||
|
||||
private String fromId;
|
||||
|
||||
private String toId;
|
||||
|
||||
private String ownerId;
|
||||
|
||||
/** messageBodyId*/
|
||||
private Long messageKey;
|
||||
/** 序列号*/
|
||||
private Long sequence;
|
||||
|
||||
private String messageRandom;
|
||||
|
||||
private Long messageTime;
|
||||
|
||||
private Long createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.lld.message.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lld.message.dao.ImGroupMessageHistoryEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ImGroupMessageHistoryMapper extends BaseMapper<ImGroupMessageHistoryEntity> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.lld.message.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lld.message.dao.ImMessageBodyEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
@Repository
|
||||
public interface ImMessageBodyMapper extends BaseMapper<ImMessageBodyEntity> {
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.lld.message.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lld.message.dao.ImMessageHistoryEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collection;
|
||||
@Repository
|
||||
public interface ImMessageHistoryMapper extends BaseMapper<ImMessageHistoryEntity> {
|
||||
|
||||
/**
|
||||
* 批量插入(mysql)
|
||||
* @param entityList
|
||||
* @return
|
||||
*/
|
||||
Integer insertBatchSomeColumn(Collection<ImMessageHistoryEntity> entityList);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.lld.message.model;
|
||||
|
||||
import com.lld.im.common.model.message.GroupChatMessageContent;
|
||||
import com.lld.im.common.model.message.MessageContent;
|
||||
import com.lld.message.dao.ImMessageBodyEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: Chackylee
|
||||
* @description:
|
||||
**/
|
||||
@Data
|
||||
public class DoStoreGroupMessageDto {
|
||||
|
||||
private GroupChatMessageContent groupChatMessageContent;
|
||||
|
||||
private ImMessageBodyEntity imMessageBodyEntity;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.lld.message.model;
|
||||
|
||||
import com.lld.im.common.model.message.MessageContent;
|
||||
import com.lld.message.dao.ImMessageBodyEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: Chackylee
|
||||
* @description:
|
||||
**/
|
||||
@Data
|
||||
public class DoStoreP2PMessageDto {
|
||||
|
||||
private MessageContent messageContent;
|
||||
|
||||
private ImMessageBodyEntity imMessageBodyEntity;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.lld.message.mq;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.lld.im.common.constant.Constants;
|
||||
import com.lld.message.dao.ImMessageBodyEntity;
|
||||
import com.lld.message.model.DoStoreGroupMessageDto;
|
||||
import com.lld.message.model.DoStoreP2PMessageDto;
|
||||
import com.lld.message.service.StoreMessageService;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.support.AmqpHeaders;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: lld
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class StroeGroupMessageReceiver {
|
||||
private static Logger logger = LoggerFactory.getLogger(StroeGroupMessageReceiver.class);
|
||||
|
||||
@Autowired
|
||||
StoreMessageService storeMessageService;
|
||||
|
||||
@RabbitListener(
|
||||
bindings = @QueueBinding(
|
||||
value = @Queue(value = Constants.RabbitConstants.StoreGroupMessage,durable = "true"),
|
||||
exchange = @Exchange(value = Constants.RabbitConstants.StoreGroupMessage,durable = "true")
|
||||
),concurrency = "1"
|
||||
)
|
||||
public void onChatMessage(@Payload Message message,
|
||||
@Headers Map<String,Object> headers,
|
||||
Channel channel) throws Exception {
|
||||
String msg = new String(message.getBody(),"utf-8");
|
||||
logger.info("CHAT MSG FORM QUEUE ::: {}", msg);
|
||||
Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG);
|
||||
try {
|
||||
JSONObject jsonObject = JSON.parseObject(msg);
|
||||
DoStoreGroupMessageDto doStoreGroupMessageDto = jsonObject.toJavaObject(DoStoreGroupMessageDto.class);
|
||||
ImMessageBodyEntity messageBody = jsonObject.getObject("messageBody", ImMessageBodyEntity.class);
|
||||
doStoreGroupMessageDto.setImMessageBodyEntity(messageBody);
|
||||
storeMessageService.doStoreGroupMessage(doStoreGroupMessageDto);
|
||||
channel.basicAck(deliveryTag, false);
|
||||
}catch (Exception e){
|
||||
logger.error("处理消息出现异常:{}", e.getMessage());
|
||||
logger.error("RMQ_CHAT_TRAN_ERROR", e);
|
||||
logger.error("NACK_MSG:{}", msg);
|
||||
//第一个false 表示不批量拒绝,第二个false表示不重回队列
|
||||
channel.basicNack(deliveryTag, false, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.lld.message.mq;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.lld.im.common.constant.Constants;
|
||||
import com.lld.message.dao.ImMessageBodyEntity;
|
||||
import com.lld.message.model.DoStoreP2PMessageDto;
|
||||
import com.lld.message.service.StoreMessageService;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.support.AmqpHeaders;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: lld
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class StroeP2PMessageReceiver {
|
||||
private static Logger logger = LoggerFactory.getLogger(StroeP2PMessageReceiver.class);
|
||||
|
||||
@Autowired
|
||||
StoreMessageService storeMessageService;
|
||||
|
||||
@RabbitListener(
|
||||
bindings = @QueueBinding(
|
||||
value = @Queue(value = Constants.RabbitConstants.StoreP2PMessage,durable = "true"),
|
||||
exchange = @Exchange(value = Constants.RabbitConstants.StoreP2PMessage,durable = "true")
|
||||
),concurrency = "1"
|
||||
)
|
||||
public void onChatMessage(@Payload Message message,
|
||||
@Headers Map<String,Object> headers,
|
||||
Channel channel) throws Exception {
|
||||
String msg = new String(message.getBody(),"utf-8");
|
||||
logger.info("CHAT MSG FORM QUEUE ::: {}", msg);
|
||||
Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG);
|
||||
try {
|
||||
JSONObject jsonObject = JSON.parseObject(msg);
|
||||
DoStoreP2PMessageDto doStoreP2PMessageDto = jsonObject.toJavaObject(DoStoreP2PMessageDto.class);
|
||||
ImMessageBodyEntity messageBody = jsonObject.getObject("messageBody", ImMessageBodyEntity.class);
|
||||
doStoreP2PMessageDto.setImMessageBodyEntity(messageBody);
|
||||
storeMessageService.doStoreP2PMessage(doStoreP2PMessageDto);
|
||||
channel.basicAck(deliveryTag, false);
|
||||
}catch (Exception e){
|
||||
logger.error("处理消息出现异常:{}", e.getMessage());
|
||||
logger.error("RMQ_CHAT_TRAN_ERROR", e);
|
||||
logger.error("NACK_MSG:{}", msg);
|
||||
//第一个false 表示不批量拒绝,第二个false表示不重回队列
|
||||
channel.basicNack(deliveryTag, false, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.lld.message.service;
|
||||
|
||||
import com.lld.im.common.model.message.GroupChatMessageContent;
|
||||
import com.lld.im.common.model.message.MessageContent;
|
||||
import com.lld.message.dao.ImGroupMessageHistoryEntity;
|
||||
import com.lld.message.dao.ImMessageBodyEntity;
|
||||
import com.lld.message.dao.ImMessageHistoryEntity;
|
||||
import com.lld.message.dao.mapper.ImGroupMessageHistoryMapper;
|
||||
import com.lld.message.dao.mapper.ImMessageBodyMapper;
|
||||
import com.lld.message.dao.mapper.ImMessageHistoryMapper;
|
||||
import com.lld.message.model.DoStoreGroupMessageDto;
|
||||
import com.lld.message.model.DoStoreP2PMessageDto;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: lld
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class StoreMessageService {
|
||||
|
||||
@Autowired
|
||||
ImMessageHistoryMapper imMessageHistoryMapper;
|
||||
|
||||
@Autowired
|
||||
ImMessageBodyMapper imMessageBodyMapper;
|
||||
|
||||
@Autowired
|
||||
ImGroupMessageHistoryMapper imGroupMessageHistoryMapper;
|
||||
|
||||
|
||||
@Transactional
|
||||
public void doStoreP2PMessage(DoStoreP2PMessageDto doStoreP2PMessageDto){
|
||||
imMessageBodyMapper.insert(doStoreP2PMessageDto.getImMessageBodyEntity());
|
||||
List<ImMessageHistoryEntity> imMessageHistoryEntities = extractToP2PMessageHistory(doStoreP2PMessageDto.getMessageContent(), doStoreP2PMessageDto.getImMessageBodyEntity());
|
||||
imMessageHistoryMapper.insertBatchSomeColumn(imMessageHistoryEntities);
|
||||
}
|
||||
|
||||
|
||||
public List<ImMessageHistoryEntity> extractToP2PMessageHistory(MessageContent messageContent,
|
||||
ImMessageBodyEntity imMessageBodyEntity){
|
||||
List<ImMessageHistoryEntity> list = new ArrayList<>();
|
||||
ImMessageHistoryEntity fromHistory = new ImMessageHistoryEntity();
|
||||
BeanUtils.copyProperties(messageContent,fromHistory);
|
||||
fromHistory.setOwnerId(messageContent.getFromId());
|
||||
fromHistory.setMessageKey(imMessageBodyEntity.getMessageKey());
|
||||
fromHistory.setCreateTime(System.currentTimeMillis());
|
||||
fromHistory.setSequence(messageContent.getMessageSequence());
|
||||
|
||||
ImMessageHistoryEntity toHistory = new ImMessageHistoryEntity();
|
||||
BeanUtils.copyProperties(messageContent,toHistory);
|
||||
toHistory.setOwnerId(messageContent.getToId());
|
||||
toHistory.setMessageKey(imMessageBodyEntity.getMessageKey());
|
||||
toHistory.setCreateTime(System.currentTimeMillis());
|
||||
toHistory.setSequence(messageContent.getMessageSequence());
|
||||
|
||||
list.add(fromHistory);
|
||||
list.add(toHistory);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void doStoreGroupMessage(DoStoreGroupMessageDto doStoreGroupMessageDto) {
|
||||
imMessageBodyMapper.insert(doStoreGroupMessageDto.getImMessageBodyEntity());
|
||||
ImGroupMessageHistoryEntity imGroupMessageHistoryEntity = extractToGroupMessageHistory(doStoreGroupMessageDto.getGroupChatMessageContent(),doStoreGroupMessageDto.getImMessageBodyEntity());
|
||||
imGroupMessageHistoryMapper.insert(imGroupMessageHistoryEntity);
|
||||
|
||||
}
|
||||
|
||||
private ImGroupMessageHistoryEntity extractToGroupMessageHistory(GroupChatMessageContent
|
||||
messageContent , ImMessageBodyEntity messageBodyEntity){
|
||||
ImGroupMessageHistoryEntity result = new ImGroupMessageHistoryEntity();
|
||||
BeanUtils.copyProperties(messageContent,result);
|
||||
result.setGroupId(messageContent.getGroupId());
|
||||
result.setMessageKey(messageBodyEntity.getMessageKey());
|
||||
result.setCreateTime(System.currentTimeMillis());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
|
||||
|
||||
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
password: frfr46467979+
|
||||
url: jdbc:mysql://127.0.0.1:3306/im-core?serverTimezone=UTC&useSSL=false&characterEncoding=UTF8
|
||||
username: root
|
||||
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
jedis:
|
||||
pool:
|
||||
max-active: 100
|
||||
max-idle: 100
|
||||
max-wait: 1000
|
||||
min-idle: 10
|
||||
password:
|
||||
rabbitmq:
|
||||
host: localhost
|
||||
port: 5672
|
||||
addresses: localhost
|
||||
username: guest
|
||||
password: guest
|
||||
# virtual-host:
|
||||
listener:
|
||||
simple:
|
||||
concurrency: 5
|
||||
max-concurrency: 10
|
||||
acknowledge-mode: MANUAL
|
||||
prefetch: 1
|
||||
publisher-confirms: true
|
||||
publisher-returns: true
|
||||
template:
|
||||
mandatory: true
|
||||
cache:
|
||||
connection:
|
||||
mode: channel
|
||||
channel:
|
||||
size: 36
|
||||
checkout-timeout: 0
|
||||
|
||||
|
||||
|
||||
# logger 配置
|
||||
logging:
|
||||
config: classpath:logback-spring.xml
|
||||
|
||||
|
||||
mybatis-plus:
|
||||
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
mapper-locations: classpath*:mapper/*.xml
|
||||
global-config:
|
||||
db-config:
|
||||
update-strategy: NOT_EMPTY
|
||||
|
||||
#mybatis:
|
||||
# configuration:
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
@@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<!-- 日志级别从低到高分为TRACE < DEBUG < INFO < WARN < ERROR < FATAL,如果设置为WARN,则低于WARN的信息都不会输出 -->
|
||||
<!-- scan:当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true -->
|
||||
<!-- scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 -->
|
||||
<!-- debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
|
||||
|
||||
<configuration scan="true" scanPeriod="10 seconds" >
|
||||
|
||||
<include resource="org/springframework/boot/logging/logback/defualts.xml"/>
|
||||
|
||||
<springProperty scope="context" name="springAppName" source="spring.application.name"/>
|
||||
<springProperty scope="context" name="springAppEnv" source="spring.profiles.active"/>
|
||||
<!-- <springProperty scope="context" name="logFile" source="logging.file"/> -->
|
||||
|
||||
<property name="logFile" value="logs/mylog.log"/>
|
||||
<!--日志在工程中的输出位置-->
|
||||
<property name="LOG_FILE" value="${logFile}"/>
|
||||
<!-- 彩色日志依赖的渲染类 -->
|
||||
<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"/>
|
||||
<!--控制台的日志输出样式-->
|
||||
<property name="CONSOLE_LOG_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([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||
|
||||
|
||||
<!--控制台 Appender-->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>DEBUG</level>
|
||||
</filter>
|
||||
<encoder>
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
<charset>utf8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<!--隐藏服务发现后输出的日志-->
|
||||
<logger name="com.netflix.discovery.shared.resolver.aws.ConfigClusterResolver" level="WARN"/>
|
||||
<logger name="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" level="WARN"/>
|
||||
|
||||
|
||||
<springProfile name="test,dev">
|
||||
<!--文件-->
|
||||
<appender name="fileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<Prudent>true</Prudent>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<FileNamePattern>
|
||||
${logFile}.%d{yyyy-MM-dd}.log
|
||||
</FileNamePattern>
|
||||
</rollingPolicy>
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>
|
||||
%d{yyyy-MM-dd HH:mm:ss} -%msg%n
|
||||
</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
<root level="INFO">
|
||||
<appender-ref ref="console"/>
|
||||
<appender-ref ref="fileAppender"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
<springProfile name="prod">
|
||||
<!--文件-->
|
||||
<appender name="fileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<Prudent>true</Prudent>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<FileNamePattern>
|
||||
${logFile}.%d{yyyy-MM-dd}.log
|
||||
</FileNamePattern>
|
||||
</rollingPolicy>
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>
|
||||
%d{yyyy-MM-dd HH:mm:ss} -%msg%n
|
||||
</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
<root level="WARN">
|
||||
<appender-ref ref="console"/>
|
||||
<appender-ref ref="fileAppender"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user