Easy Logger is a library that provide Kotlin extensions for Android logging.
No need to configure log level, just gradle link to the matching dependency.
If is not specified, Log tag is automatically generated with name of the class and current method.
build.gradle
configuration file :
repositories {
jcenter()
}
dependencies {
// Choose log level with matching dependency
implementation 'com.radiofrance.android:log-noop:x.x.x'
implementation 'com.radiofrance.android:log-verbose:x.x.x'
implementation 'com.radiofrance.android:log-debug:x.x.x'
implementation 'com.radiofrance.android:log-info:x.x.x'
implementation 'com.radiofrance.android:log-warning:x.x.x'
implementation 'com.radiofrance.android:log-error:x.x.x'
}
Example :
No Operation
forRelease
variantVerbose
forDebug
variant.
dependencies {
releaseImplementation 'com.radiofrance.android:log-noop:x.x.x'
debugImplementation 'com.radiofrance.android:log-verbose:x.x.x'
}
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
logv()
// Logcat output : "V/MainActivity::onCreate: "
logv("logv with message")
// Logcat output : "V/MainActivity::onCreate: logv with message"
logv("LOG_TAG", "logv with makeLogTag and message")
// Logcat output : "V/LOG_TAG: logv with makeLogTag and message"
logv("logv message and exception", Exception("Exception message"))
// Logcat output : "V/MainActivity::onCreate: logv message and exception
// java.lang.Exception: Exception message
// at com.radiofrance.logger.demo.MainActivity.onCreate(MainActivity.kt:20)
// at android.app.Activity.performCreate(Activity.java:6679)
// at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
// at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)"
logv("LOG_TAG", "logv with makeLogTag, message and exception", Exception("Exception message"))
// Logcat output : "V/LOG_TAG: logv message and exception
// java.lang.Exception: Exception message
// at com.radiofrance.logger.demo.MainActivity.onCreate(MainActivity.kt:20)
// at android.app.Activity.performCreate(Activity.java:6679)
// at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
// at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)"
// Logs on other levels
logd()
logd("logd with message")
logd("LOG_TAG", "logd with makeLogTag and message")
logd("logd message and exception", Exception("Exception message"))
logd("LOG_TAG", "logd with makeLogTag, message and exception", Exception("Exception message"))
logi()
logi("logi with message")
logi("LOG_TAG", "logi with makeLogTag and message")
logi("logi message and exception", Exception("Exception message"))
logi("LOG_TAG", "logi with makeLogTag, message and exception", Exception("Exception message"))
logw()
logw("logw with message")
logw("LOG_TAG", "logw with makeLogTag and message")
logw("logw message and exception", Exception("Exception message"))
logw("LOG_TAG", "logw with makeLogTag, message and exception", Exception("Exception message"))
loge()
loge("loge with message")
loge("LOG_TAG", "loge with makeLogTag and message")
loge("loge message and exception", Exception("Exception message"))
loge("LOG_TAG", "loge with makeLogTag, message and exception", Exception("Exception message"))
}
}
Run all levels test
> ./gradlew runAllTests
Copyright 2019 radiofrance
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.