From 4887857dca36326830b297b377a2b77ca797ad22 Mon Sep 17 00:00:00 2001 From: "Johnny Miller (ZA)" Date: Sat, 19 Feb 2022 09:56:31 +0800 Subject: [PATCH] feat($Slf4j): support functional lazy debug [skip ci] --- .../springcloudstarter/function/Slf4j.java | 37 +++++++++++++++++++ .../maf/springcloudstarter/Slf4jTests.java | 29 +++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/function/Slf4j.java create mode 100644 spring-cloud-starter/src/test/java/com/jmsoftware/maf/springcloudstarter/Slf4jTests.java diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/function/Slf4j.java b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/function/Slf4j.java new file mode 100644 index 00000000..307041c4 --- /dev/null +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/function/Slf4j.java @@ -0,0 +1,37 @@ +/* + * Copyright By ZATI + * Copyright By 3a3c88295d37870dfd3b25056092d1a9209824b256c341f2cdc296437f671617 + * All rights reserved. + * + * If you are not the intended user, you are hereby notified that any use, disclosure, copying, printing, forwarding or + * dissemination of this property is strictly prohibited. If you have got this file in error, delete it from your + * system. + */ +package com.jmsoftware.maf.springcloudstarter.function; + +import org.slf4j.Logger; + +import java.util.function.Supplier; + +/** + * Description: Slf4j, change description here. + * + * @author 钟俊 (za-zhongjun), email: jun.zhong@zatech.com, date: 2/19/2022 9:04 AM + **/ +public class Slf4j { + private Slf4j() { + } + + /** + * Lazy debug. + * + * @param logger the logger + * @param supplier the string supplier + * @see com.jmsoftware.maf.springcloudstarter.Slf4jTests#lazyDebugTest() + */ + public static void lazyDebug(Logger logger, Supplier supplier) { + if (logger.isDebugEnabled()) { + logger.debug(supplier.get()); + } + } +} diff --git a/spring-cloud-starter/src/test/java/com/jmsoftware/maf/springcloudstarter/Slf4jTests.java b/spring-cloud-starter/src/test/java/com/jmsoftware/maf/springcloudstarter/Slf4jTests.java new file mode 100644 index 00000000..c7349d7a --- /dev/null +++ b/spring-cloud-starter/src/test/java/com/jmsoftware/maf/springcloudstarter/Slf4jTests.java @@ -0,0 +1,29 @@ +/* + * Copyright By ZATI + * Copyright By 3a3c88295d37870dfd3b25056092d1a9209824b256c341f2cdc296437f671617 + * All rights reserved. + * + * If you are not the intended user, you are hereby notified that any use, disclosure, copying, printing, forwarding or + * dissemination of this property is strictly prohibited. If you have got this file in error, delete it from your + * system. + */ +package com.jmsoftware.maf.springcloudstarter; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import static com.jmsoftware.maf.springcloudstarter.function.Slf4j.lazyDebug; + +/** + * Description: Slf4jTests, change description here. + * + * @author 钟俊 (za-zhongjun), email: jun.zhong@zatech.com, date: 2/19/2022 9:16 AM + **/ +@Slf4j +class Slf4jTests { + @Test + void lazyDebugTest() { + Assertions.assertDoesNotThrow(() -> lazyDebug(log, () -> "Hello World! From lazyDebug test.")); + } +}