Git Product home page Git Product logo

logcat's Introduction

Logcat

Download

一个 Java 平台的简易的 log 工具。 可用于 Java、 kotlin、 Android。共三个模块, logcat 是基础包, logcat4kt, 是kotlin 的扩展, logcat4Android 内置了 AndroidLogcatHandler(使用安卓内置的Log工具输出)。

集成

添加仓库

maven { url "https://dl.bintray.com/lt-123/maven" }

添加依赖

Java

compile 'xyz.liut.logcat:logcat:版本号'

kotlin

compile 'xyz.liut.logcat:logcat:版本号'
compile 'xyz.liut.logcat:logcat4kt:版本号'

android

implementation 'xyz.liut.logcat:logcat:版本号'
implementation 'xyz.liut.logcat:logcat4kt:版本号'
implementation 'xyz.liut.logcat:logcat4android:版本号'

使用

初始化-以kotlin为例,Java也一样

L
    .getDefault()
    // 等级
    .setLevel(LogLevel.VERBOSE)
    //输出到控制台
    .addHandler(AndroidLogcatHandler("LOGCAT_" + Process.myPid() + "_"))
    // 标准输出 System.out
    .addHandler(StdHandler(false, true, false))
    // 输出到文件
    .addHandler(
        RollbackFileHandler(
            getExternalFilesDir("logcat").toString(),
            1,
            "yyyy-MM-dd-HH-mm-ss'.log'"
        )
    )
    // 自定义输出,到屏幕
    .addHandler { _, tag, msg ->
        runOnUiThread {
            with(tv_txt) {
                append("\n")
                append(tag)
                append(": ")
                append(msg)
            }
        }
    }

输出日志-Java

L.v("verbose");
L.v("tag", "verbose");
L.d("debug");
L.d("tag", "debug");
L.i("info");
L.i("tag", "info");
L.w("warn");
L.w("tag", "warn");
L.w("tag", "warn", new Throwable("warn test"));
L.w("warn", new Throwable("warn test"));
L.e("error");
L.e("tag", "error");
L.e("tag", "error", new Throwable("error test"));
L.e("warn", new Throwable("error test"));
L.wtf("wtf");
L.wtf("tag", "wtf");
L.wtf("tag", "wtf", new Throwable("wtf test"));
L.wtf("wtf", new Throwable("wtf test"));
L.wtf(new Throwable("wtf test"));

输出日志-kotlin

logVerbose { "verbose" }
logDebug { "debug" }
logInfo { "info" }
logWarn { "warn" }
logError { "error" }
logWtf { "what the fuck" }

logVerbose("tag") { "verbose" }
logDebug("tag") { "debug" }
logInfo("tag") { "info" }
logWarn("tag") { "warn" }
logError("tag") { "error" }
logWtf("tag") { "what the fuck" }

NullPointerException("npe").printLogcat()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.