Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fast是一款Android的方法被调用时自动日志记录的Debug工具,支持Java和Kotlin语言

License

Notifications You must be signed in to change notification settings

qq877693928/Fast

Repository files navigation

Fast

Download ASL 2.0

Fast是一款Android的Debug工具,支持Java和Kotlin语言, 通过注解标注待打点方法,程序运行时该方法被调用时,自动触发日志记录到Logcat , 记录信息包括进入该方法名称、方法的类型和参数值以及方法执行的时长

⚠️ 因为使用Gradle Transform,仅支持包含 id 'com.android.library'id 'com.android.application' 的 Module,不支持 id 'java-library' 的 Module,使用 FastLog 时需将 id 'java-library' 转成 id 'com.android.library'

在开发过程中,有时我们不希望通过Cpu Profiler 工具查看方法的调用过程同时又想快速了解方法的执行过程、参数和时间,就需要对方法的打日志,打日志是一个繁琐的过程,需要记录方法开始时间,参数值,结束时计算方法执行时长,如果待打点的方法比较多时就特别繁琐。

Fast通过在方法上加上特定注解(@FastLog),编译时自动插入代码,记录该方法被调用时的关键信息,省去开发者手写打点代码,从而提升了开发效率

效果

示例代码

 @FastLog
 private fun testHello(first: String, second: String): String {
 return "$first $second"
 }
  • 日志效果
 D/FAST_LOG: ├[main]-->> MainActivity#testHello(String="hello", String="world")
 D/FAST_LOG: ├[main]--<< MainActivity#testHello() [1ms]

工具集成

  1. 工程目录build.gradle添加repositories和classpath build.gradle配置参考

工具jar已发布至MavenCentral,需添加mavenCentral()

repositories {
 ...
 mavenCentral()
}

然后添加classpath

buildscript {
 ...
 dependencies {
 classpath 'io.github.qq877693928:fast-plugin:2.4.0'
 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:xxx"
 }
}
  1. 需要使用的app的build.gradle添加apply plugin
apply plugin: 'com.lizhenhua.fast.plugin'

或者

plugins {
 ...
 id 'com.lizhenhua.fast.plugin'
}

添加混淆

-keep class com.lizhenhua.fast.**{*;}

依赖支持库

dependencies {
 ...
 implementation 'io.github.qq877693928:fast-runtime:2.4.0'
 implementation 'io.github.qq877693928:fast-annotation:2.4.0'
 ...
}
  1. 在需要打点的方法上添加标注, Demo参考

配置(Since fast-plugin:1.0.1)

由于在编译过程中需要将所有加上@FastLog注解的方法都会注入代码,为了避免Release版本打包效率问题和Release版本安全性等问题,所有在Release版本上需要将注入代码的功能去掉

从fast-plugin:1.0.1起提供gradle自定义fast配置, enable值默认为true表示@FastLog注解的方法会注入代码,为false时表示不会注入代码

如下:

fast {
 enable = true
}

build.gradle 脚本配置debug版本生效(忽略AndroidTest和UnitTest):

allprojects { subProject ->
 def taskName = project.gradle.startParameter.taskNames != null
 ? project.gradle.startParameter.taskNames.toString() : "[]"
 if (!taskName.contains("AndroidTest")
 && !taskName.contains("UnitTest")
 && taskName.contains("Debug")) {
 apply plugin: 'com.lizhenhua.fast.plugin'
 fast {
 enable = true
 }
 }
}

About

Fast是一款Android的方法被调用时自动日志记录的Debug工具,支持Java和Kotlin语言

Resources

License

Stars

Watchers

Forks

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /