Skip to content

Commit

Permalink
feat($Slf4j): support functional lazy debug
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
johnnymillergh committed Feb 19, 2022
1 parent e0fc588 commit 4887857
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
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());
}
}
}
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."));
}
}

0 comments on commit 4887857

Please sign in to comment.