我在开发中使用了
Logger库,并在Application类中配置它:
@Override public void onCreate() { super.onCreate(); sInstance = this; Logger.init(BuildConfig.LOGGER_TAG_NAME) //.setMethodCount(3) // default 2 //.hideThreadInfo() // default shown .setLogLevel(LogLevel.NONE); // default LogLevel.FULL
LogLevel是一个枚举(在Logger库中).
但我想根据我的gradle构建类型自动设置日志级别;做那样的事情:
buildTypes { debug { debuggable true buildConfigField "enum","LOGGER_LEVEL",LogLevel.FULL } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro' buildConfigField "enum",LogLevel.NONE } }
然后:
Logger.init(BuildConfig.LOGGER_TAG_NAME) //.setMethodCount(3) // default 2 //.hideThreadInfo() // default shown .setLogLevel(BuildConfig.LOGGER_LEVEL); // default LogLevel.FULL
但它不起作用:
Error:(31,0) No such property: NONE for class: org.gradle.api.logging.LogLevel
它与FULL枚举值相同.
谢谢你的帮助!
解决方法
您必须在属性类型和值中包含包和类名:
buildTypes { debug { debuggable true buildConfigField "com.orhanobut.logger.LogLevel","com.orhanobut.logger.LogLevel.FULL" } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro' buildConfigField "com.orhanobut.logger.LogLevel","com.orhanobut.logger.LogLevel.NONE" } }