I use Logger library in my development, and I configure it in my Application class:
@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 is an enum (in Logger library).
But I want automatically to set the log level according my gradle build type; to do something like that:
buildTypes {
debug {
debuggable true
buildConfigField "enum", "LOGGER_LEVEL", LogLevel.FULL
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "enum", "LOGGER_LEVEL", LogLevel.NONE
}
}
then:
Logger.init(BuildConfig.LOGGER_TAG_NAME)
//.setMethodCount(3) // default 2
//.hideThreadInfo() // default shown
.setLogLevel(BuildConfig.LOGGER_LEVEL); // default LogLevel.FULL
But it doesn't work:
Error:(31, 0) No such property: NONE for class: org.gradle.api.logging.LogLevel
It's the same with FULL enum value.
Thanks for your help guys !
You must include the package and class name in both, property type and value:
buildTypes {
debug {
debuggable true
buildConfigField "com.orhanobut.logger.LogLevel", "LOGGER_LEVEL", "com.orhanobut.logger.LogLevel.FULL"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "com.orhanobut.logger.LogLevel", "LOGGER_LEVEL", "com.orhanobut.logger.LogLevel.NONE"
}
}
To avoid having to repeat the package name and to make the lines shorter, you can define some variable, like:
def LogLevel = "com.orhanobut.logger.LogLevel"
buildTypes {
debug {
debuggable true
buildConfigField LogLevel, "LOGGER_LEVEL", "${LogLevel}.FULL"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField LogLevel, "LOGGER_LEVEL", "${LogLevel}.NONE"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With