refactor: extend logcat to include tag.

This way can filter and tag the logs.

Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
KaiserBh 2024-01-08 06:48:58 +11:00
parent 6e5d67b449
commit e1eb2e3a86
No known key found for this signature in database
GPG Key ID: 14D73B142042BBA9

View File

@ -7,12 +7,23 @@ import logcat.logcat
inline fun Any.logcat( inline fun Any.logcat(
priority: LogPriority = LogPriority.DEBUG, priority: LogPriority = LogPriority.DEBUG,
throwable: Throwable? = null, throwable: Throwable? = null,
tag: String? = null,
message: () -> String = { "" }, message: () -> String = { "" },
) = logcat(priority = priority) { ) = logcat(priority = priority) {
var msg = message() val logMessage = StringBuilder()
if (throwable != null) {
if (msg.isNotBlank()) msg += "\n" if (!tag.isNullOrEmpty()) {
msg += throwable.asLog() logMessage.append("[$tag] ")
} }
msg
val msg = message()
logMessage.append(msg)
if (throwable != null) {
if (msg.isNotBlank()) logMessage.append("\n")
logMessage.append(throwable.asLog())
}
logMessage.toString()
} }