-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($Slf4j): support functional lazy debug
[skip ci]
- Loading branch information
1 parent
e0fc588
commit 4887857
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/function/Slf4j.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> supplier) { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug(supplier.get()); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
spring-cloud-starter/src/test/java/com/jmsoftware/maf/springcloudstarter/Slf4jTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.")); | ||
} | ||
} |