加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

README.org

介绍

LogTrace插件,用AspectJ切入log,

...
@LogTrace(level = 2)
public int add3(int a) {
    return a + 3;
}
...

结果如下:

DEBUG: Test01: ⇢ add3(a=7) [Thread:"main"]
DEBUG: Test01: ⇠ add3 [0ms] = 10

工程目录

用法

运行gradle -b LogTrace-Plugin/deploy.gradle uploadArchives 发布

用本地的仓库

apply plugin: 'logtrace'

buildscript {
    dependencies {
        classpath group: 'com.logtrace', name: 'LogTrace-Plugin', version: '1.0-SNAPSHOT'
    }
}

dependencies {
    compile group: 'com.logtrace', name: 'LogTrace-Plugin', version: '1.0-SNAPSHOT'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

logtrace {
    enabled = true
    compileJavas = [compileJava]
    compileTestJavas = [compileJava, compileTestJava]
}

用远程仓库

apply plugin: 'java'
apply plugin: 'logtrace'

sourceCompatibility = 1.8
targetCompatibility = 1.8

buildscript {
    repositories {
        jcenter()
        maven {url "https://raw.github.com/ttt307307/mvn-repo/master/"}
    }
    dependencies {
        classpath group: 'com.logtrace', name: 'LogTrace-Plugin', version: '1.0-SNAPSHOT'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {url "https://raw.github.com/ttt307307/mvn-repo/master/"}
    }
}

logtrace {
    enabled = true
    compileJavas = [compileJava]
    compileTestJavas = [compileTestJava]
}


sourceSets {
    main {
        java {
            srcDirs = ['src/main/java']

        }
        resources {
            srcDirs = ['src/main/resources']
        }
    }
    test {
        java {
            srcDirs = ['src/junit/java','src/testng/java']
        }
        resources {
            srcDirs = ['src/junit/resources']
        }
    }
}

dependencies {
    compile group: 'com.logtrace', name: 'LogTrace-Plugin', version: '1.0-SNAPSHOT'

    testCompile group: 'junit', name: 'junit', version: '4.11'
    testCompile group: 'org.testng', name: 'testng', version: '6.9.9'
    testCompile 'org.mockito:mockito-core:1.10.19'
}

Java工程

Java工程参考 LogTraceDemoLogTraceDemo-Remote-Repo

sourceCompatibility = 1.8
targetCompatibility = 1.8

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    repositories {
        flatDir {
            name 'localRepository'
        }
    }
    repositories {
        localRepository {
            dirs '../local-repo'
        }
    }
    dependencies {
        classpath group: 'com.logtrace', name: 'LogTrace-Plugin', version: '1.0-SNAPSHOT'
    }
}
allprojects {
    repositories {
        jcenter()
        flatDir {
            name 'localRepository'
        }
        localRepository {
            dirs '../local-repo'
        }
    }
}

logtrace {
    enabled = true
    compileJavas = [compileJava]
    compileTestJavas = [compileJava, compileTestJava]
}

Android工程

Android工程参考 logtracedemo-and

apply plugin: 'com.android.application'

apply plugin: 'logtrace'

sourceCompatibility = 1.7
targetCompatibility = 1.7

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    repositories {
        flatDir {
            name 'localRepository'
        }
    }
    repositories {
        localRepository {
            dirs '../local-repo'
        }
    }
    dependencies {
        classpath group: 'com.logtrace', name: 'LogTrace-Plugin', version: '1.0-SNAPSHOT'
    }
}
allprojects {
    repositories {
        jcenter()
        flatDir {
            name 'localRepository'
        }
        localRepository {
            dirs '../local-repo'
        }
    }
}
logtrace {
    enabled = true
}

//Application
project.android.applicationVariants.all { variant ->
    variant.each {
        logtrace.compileJavas.add(variant.javaCompile)
    }
}

//如果是Library
//project.android.libraryVariants.all { variant ->
//    variant.each {
//        logtrace.compileJavas.add(variant.javaCompile)
//    }
//}

project.android.testVariants.all { variant ->
    variant.each {
        logtrace.compileTestJavas.add(variant.javaCompile)
    }
}

参考:

参考JakeWharton/hugo

问题(TODO)

  • 在build.gradle中配置一个level来过滤log
  • 安卓闪退 java.lang.NoSuchMethodError: No virtual method getDeclaredAnnotation(Ljava/lang/Class;)Ljava/lang/annotation/Annotation; in class Ljava/lang/reflect/Method; or its super classes (declaration of ‘java.lang.reflect.Method’ appears in /system/framework/core-libart.jar),可能和设置的jdk版本有关,现在改为编译java文件的JDK版本为1.7

空文件

简介

LogTrace gradle插件,通过ajc切入日志 展开 收起
Java
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化