Java 日志工具 (Cloudopt-Logger)

Cloudopt-logger是一个基于Kotlin的可扩展和可配置的日志框架扩展,支持Java,Kotlin和Android。

https://github.com/cloudoptlab/cloudopt-logger

在Java中是使用

添加依赖

    compile 'net.cloudopt.logger:cloudopt-logger:1.0.1'
    compile 'org.slf4j:slf4j-api:1.7.25'
    compile 'ch.qos.logback:logback-classic:1.2.3'
  1. 官网使用示例
public class TestJavaCase {
    private Logger logger = Logger.Companion.getLogger(TestCase.class);

    @Test
    public void example1() {
        logger.debug("Start init....");
        logger.info("Operation successful!");
        logger.warn("The value must be not nul.");
        logger.error("Unable to acquire lock!");
    }

    @Test
    public void example2() {
        logger.info("Please Wait.... " + Colorer.INSTANCE.blue("100"));
        logger.info("Please Wait.... " + Colorer.INSTANCE.yellow("200"));
        logger.info("Please Wait.... " + Colorer.INSTANCE.red("300"));
    }

    @Test
    public void example3() {
        LoggerConfiguration configuration = new LoggerConfiguration();
        configuration.setColor(false);
        Logger.Companion.setConfiguration(configuration);
        example1();
    }

    @Test
    public void example4() {
        LoggerConfiguration configuration = new LoggerConfiguration();
        configuration.setDebugPrefix("DEBUG");
        configuration.setInfoPrefix("INFO");
        configuration.setWarnPrefix("WARN");
        configuration.setErrorPrefix("ERROR");
        Logger.Companion.setConfiguration(configuration);
        example1();
    }
}

  1. 测试使用示例
import com.google.common.base.Joiner;
import net.cloudopt.logger.Colorer;
import net.cloudopt.logger.Logger;

public class StringTest {

    private static Logger logger = Logger.Companion.getLogger(StringTest.class);

    public static void main(String[] args) {

        // skipNulls() 跳过null
        // useForNull("rep") 使用给定的字符替换null
        Joiner joiner = Joiner.on("; ").skipNulls();
        String str = joiner.join("Harry", null, "Ron", "Hermione");

        logger.info(str);
        logger.warn(str);
        logger.debug(str);
        logger.error(str);
        // 自定义日志颜色
        logger.info(Colorer.INSTANCE.red(str));

    }

}

测试结果

推荐阅读更多精彩内容

  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 11,623评论 2 56
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 167,979评论 26 707
  • 湖北省首批师承中医,中医“衡法”理论第一人。 1953年生于江汉平原区中医世家,自小聪慧爱学,读古今善书,少年天才...
    中医刘少甲阅读 596评论 0 1
  • 自私地活着 2016年11月30日 早上六点多就起来,步行上班去。走在川流不息的忙忙碌碌的人群中,有种高大上的感...
    夏花静秋阅读 173评论 1 2
  • 我是没有什么高尚趣好的人,但是凡小家子气的东西,便多少喜欢一点,尤其好听闲话。 虽然父母从小教养的和寻常家...
    f5120924cbd9阅读 487评论 0 1