UltimateLogger is a library with many useful and customizable logging options.
This is Android version of UltimateLogger. JVM version, which you can use e.g. in desktop Java or Kotlin applications, is available here.
Feel free to add your suggestions, issues and pull requests!
- Add UltimateLogger dependencies to your build.gradle:
dependencies {
implementation 'com.github.ArturBorowy:ultimate-logger-android:0.1.0'
}
Unless you already have, add JitPack repository to your project level build.gradle:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Init library (you probably want to do this in
onCreate()
method of yoursApplication
class):
val shouldLog = true
val defaultTagSettings = TagSettings(
shouldLogFileNameAndLineNum = true,
shouldLogClassName = true,
shouldLogMethodName = true)
ALogInitializer.init(shouldLog, defaultTagSettings)
- Log:
ALog.d("Your message to log on debug level.")
ALog.e(Exception("Your exception to log on error level."))
- Stop library (you probably want to do this in
onDestroy()
method of yoursApplication
class)::
ALogInitializer.destroy()
- Fully customizable tag:
As I have shown before:
ALogInitializer.init(...)
method takes TagSettings object as argument:
If you set shouldLogClassName
of tagSettings
flag to true
, you will see class name before message in every line logged. shouldLogFileNameAndLineNum
is a cool feature too. If you set this flag to true
, you will see in Logcat a hyperlink to the line of code, where you have used ALog (see in example of Quick start quide#2).
Optionally you can override default tag settings (you have set in ALogInitializer.init(...)) in every specific usage of ALog
ALog.d("This usage overrides tagSettings for own purpose.", true)
Above usage will log line number and file name even if default global settings are different.
- Null safety extensions with logging
No more boilerplate like this:
myObject?.let {it.doSomething()} ?: Log.w(TAG, "object is null")
// Now you can just write
myObject.tw { it.doSomething() }
- Logging
Any?
type
No more .toString()
calls on objects you want to log. UltimateLogger can log everything:
ALog.d(1)
ALog.e(2f)
ALog.v(Date())
ALog.wtf((null as String?)) // Objects of nullable types are safe to log!
ALog.e() // Empty message? No problem.