diff --git a/src/main/java/com/example/mina/Application.java b/src/main/java/com/example/mina/Application.java index 9667b32..681caa0 100644 --- a/src/main/java/com/example/mina/Application.java +++ b/src/main/java/com/example/mina/Application.java @@ -64,11 +64,11 @@ public class Application { MatrixClient client = clientManager.getOrCreateClient(connectConfig); -// client.setAttenuation(1,2,3, null); + client.setAttenuation(1,2,3, null); // LockSupport.parkNanos(1000_000_000); // client.setOffset(1, 2); - client.getOffset(2); +// client.getOffset(2); LockSupport.parkNanos(1000_000_000); // client.setOffset(1,2); diff --git a/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ProtocolFactory.java b/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ProtocolFactory.java index 7216584..d723b36 100644 --- a/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ProtocolFactory.java +++ b/src/main/java/com/example/mina/client/box/qrb3000/Qrb3000ProtocolFactory.java @@ -3,6 +3,7 @@ package com.example.mina.client.box.qrb3000; import com.example.mina.client.base.MatrixCommand; import com.example.mina.client.base.MatrixConstants; import com.example.mina.client.base.MatrixResponse; +import com.example.mina.processor.VbLogUtils; import com.example.mina.server.util.CommandHelper; import lombok.extern.slf4j.Slf4j; import org.apache.mina.core.buffer.IoBuffer; @@ -52,6 +53,7 @@ public class Qrb3000ProtocolFactory implements ProtocolCodecFactory { mc.getType() ); int cmd = mc.getCommand(); + VbLogUtils.infoLog(log, "", mc.getMatrixId(),msg); IoBuffer buffer = IoBuffer.allocate(100, false).setAutoExpand(true); diff --git a/src/main/java/com/example/mina/processor/LogBeanPostProcessor.java b/src/main/java/com/example/mina/processor/LogBeanPostProcessor.java new file mode 100644 index 0000000..b5abdcf --- /dev/null +++ b/src/main/java/com/example/mina/processor/LogBeanPostProcessor.java @@ -0,0 +1,30 @@ +package com.example.mina.processor; + +import lombok.extern.slf4j.Slf4j; +import org.slf4j.MDC; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class LogBeanPostProcessor implements BeanPostProcessor { + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { +// log.info("postProcessBeforeInitialization: {}", beanName); + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { +// Marker marker = MarkerFactory.getMarker("postProcessAfterInitialization"); +// MDC.put("taskId", "QRB3000/100_20210402"); +// log.info(marker, "postProcessAfterInitialization: {}", beanName); +// MDC.clear(); + return bean; + } + +} diff --git a/src/main/java/com/example/mina/processor/VbLogUtils.java b/src/main/java/com/example/mina/processor/VbLogUtils.java new file mode 100644 index 0000000..205941b --- /dev/null +++ b/src/main/java/com/example/mina/processor/VbLogUtils.java @@ -0,0 +1,30 @@ +package com.example.mina.processor; + +import org.slf4j.Logger; +import org.slf4j.MDC; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * @ProjectName: demo + * @Package: com.example.mina.processor + * @ClassName: VbLogUtils + * @Author: HuangLang + * @Description: 用于记录设备日志 + * @Date: 2021-04-01 下午 8:46 + */ +public class VbLogUtils { + public static void infoLog(Logger log, String matrixType, String matrixId, Object msg){ + Marker marker = MarkerFactory.getMarker("postProcessAfterInitialization"); + matrixType = "QRB1234"; + matrixId = "100"; + MDC.put("taskId", + matrixType + "/" + matrixId + "_" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))); + log.info("info msg, msg is: {}", msg); + MDC.clear(); + } + +} diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..b99839f --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,25 @@ + + + + + + taskId + log + + + + log/${taskId}.log + false + + %d %marker [%thread] %level %mdc %logger{35} - %msg%n + + + + + + + + + \ No newline at end of file -- libgit2 0.21.2