自定义LogUtil注解

Log打印

package com.example.framework.manager;

import android.util.Log;

import com.example.framework.BuildConfig;

public class LogUtil {

    private static String className;
    private static String methodName;
    private static int lineName;
    private static final String TAG = "Shopmall18809";

    public static void v(String message) {
        if (BuildConfig.LOG_DEBUG) {
            createLogName(new Throwable().getStackTrace());
            Log.v(TAG, className + " " + methodName + " " + lineName);
        }
    }


    public static void d(String message) {
        if (BuildConfig.LOG_DEBUG) {
            createLogName(new Throwable().getStackTrace());
            Log.d(TAG, "" + className + " " + methodName + " " + lineName + " " + message);
        }
    }
    public static void i(String message) {
        if (BuildConfig.LOG_DEBUG) {
            createLogName(new Throwable().getStackTrace());
            Log.i(TAG, className + " " + methodName + " " + lineName);
        }
    }
    public static void e(String message) {
        if (BuildConfig.LOG_ERROR) {
            createLogName(new Throwable().getStackTrace());
            Log.e(TAG, className + " " + methodName + " " + lineName);
        }
    }

    private static void createLogName(StackTraceElement[] stackTraceElements) {
        className = stackTraceElements[1].getClassName();//获取调用该log的类名,里面含有包名
        methodName = stackTraceElements[1].getMethodName();//获取调用该log的方法名
        lineName = stackTraceElements[1].getLineNumber();//获取调用该log的行数值
    }

}

build.gradle

apply plugin: 'com.android.library'
apply plugin: 'org.greenrobot.greendao' // 1.apply plugin
android {

    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    sourceSets {
        main.jniLibs.srcDirs = ['libs']
    }
    defaultConfig {
        minSdkVersion 22
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
    }

    buildTypes {

        debug{
            buildConfigField("boolean","LOG_DEBUG","false");
            buildConfigField("boolean","LOG_ERROR","false");

            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'

        }

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }


    greendao {
        // 指定数据库schema版本号,迁移等操作会用到
        schemaVersion 1
        // 设置生成数据库文件的目录,默认是在build中,可以将生成的文件放到我们的java目录中
        targetGenDir 'src/main/java'
        // 设置生成的数据库相关文件的包名,默认为entity所在的包名
        daoPackage 'com.example.framework.greendao'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'com.jakewharton:disklrucache:2.0.2'
    api 'com.blankj:utilcodex:1.26.0'
    implementation 'com.android.support:recyclerview-v7:30.0.0'//recyclerview
    implementation project(path: ':commened')
    implementation project(path: ':net')
    api 'org.greenrobot:greendao:3.3.0' // 2.add library
    //工具类
    api 'com.blankj:utilcodex:1.26.0'

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值