1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

Better logging.

This commit is contained in:
Cedric Beust 2015-10-13 18:56:29 -07:00
parent ec36ca4fa9
commit 52b3f96fce

View file

@ -70,23 +70,24 @@ fun Any.error(text: String, e: Throwable? = null) {
class Logger(val dev: Boolean) {
val FORMAT = SimpleDateFormat("HH:mm:ss.SSS")
private fun getPattern(type: String, tag: String, message: String) =
private fun getPattern(type: String, devType: String, tag: String, message: String) =
if (dev) {
val ts = FORMAT.format(Date())
"$type/$ts [" + Thread.currentThread().name + "] $tag - $message"
} else {
message
devType + message
}
final fun debug(tag: String, message: String) =
println(getPattern("D", tag, message))
println(getPattern("D", "Debug ", tag, message))
final fun error(tag: String, message: String, e: Throwable? = null) =
println(getPattern("***** E", tag, message) + " Exception: " + e?.getMessage())
println(getPattern("***** E", "***** ERROR ", tag, message) +
if (e != null) " Exception: " + e.getMessage() else "")
final fun warn(tag: String, message: String, e: Throwable? = null) =
println(getPattern("W", tag, message))
println(getPattern("W", "***** WARNING ", tag, message))
final fun log(tag: String, message: String) =
println(getPattern("L", tag, message))
println(getPattern("L", "", tag, message))
}