UltimateLogger is a library with many useful and customizable logging options.
This is JVM version of UltimateLogger. Android version, which is better choice for Android 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-jvm:0.1.0'
}
Unless you already have, add JitPack repository to your build.gradle:
repositories {
...
maven { url 'https://jitpack.io' }
}
- Init library (you probably want to do this as fast as you can):
val shouldLog = true
val defaultTagSettings = TagSettings(
shouldLogFileNameAndLineNum = true,
shouldLogClassName = true,
shouldLogMethodName = true)
JvmLogInitializer.init(shouldLog, defaultTagSettings)
- Log:
JvmLog.d("Your message to log on debug level.")
JvmLog.e(Exception("Your exception to log on error level."))
Result:
- Stop library:
JvmLogInitializer.destroy()
- Fully customizable tag:
As I have shown before:
JvmLogInitializer.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.
Optionally you can override default tag settings (you have set in JvmLogInitializer.init(...)) in every specific usage of JvmLog
JvmLog.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()} ?: OldLogger.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:
JvmLog.d(1)
JvmLog.e(2f)
JvmLog.v(Date())
JvmLog.wtf((null as String?)) // Objects of nullable types are safe to log!
JvmLog.e() // Empty message? No problem.
Result: