Improves log class for JVM
This commit is contained in:
@@ -20,16 +20,24 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.quartz.utils
|
package com.vitorpamplona.quartz.utils
|
||||||
|
|
||||||
|
import java.time.LocalTime
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
actual object Log {
|
actual object Log {
|
||||||
|
// Define a formatter for the desired output format (e.g., HH:mm:ss)
|
||||||
|
val formatter: DateTimeFormatter? = DateTimeFormatter.ofPattern("HH:mm:ss.SSS")
|
||||||
|
|
||||||
|
fun time() = LocalTime.now().format(formatter)
|
||||||
|
|
||||||
actual fun w(
|
actual fun w(
|
||||||
tag: String,
|
tag: String,
|
||||||
message: String,
|
message: String,
|
||||||
throwable: Throwable?,
|
throwable: Throwable?,
|
||||||
) {
|
) {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
println("WARN: [$tag] $message. Throwable: ${throwable.message}")
|
println("${time()} WARN : [$tag] $message. Throwable: ${throwable.message}")
|
||||||
} else {
|
} else {
|
||||||
println("WARN: [$tag] $message")
|
println("${time()} WARN : [$tag] $message")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,9 +47,9 @@ actual object Log {
|
|||||||
throwable: Throwable?,
|
throwable: Throwable?,
|
||||||
) {
|
) {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
println("ERROR: [$tag] $message. Throwable: ${throwable.message}")
|
println("${time()} ERROR: [$tag] $message. Throwable: ${throwable.message}")
|
||||||
} else {
|
} else {
|
||||||
println("ERROR: [$tag] $message")
|
println("${time()} ERROR: [$tag] $message")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,13 +57,13 @@ actual object Log {
|
|||||||
tag: String,
|
tag: String,
|
||||||
message: String,
|
message: String,
|
||||||
) {
|
) {
|
||||||
println("DEBUG: [$tag] $message")
|
println("${time()} DEBUG: [$tag] $message")
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun i(
|
actual fun i(
|
||||||
tag: String,
|
tag: String,
|
||||||
message: String,
|
message: String,
|
||||||
) {
|
) {
|
||||||
println("INFO: [$tag] $message")
|
println("${time()} INFO : [$tag] $message")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user