From 70c83c17e01d950a51326c754f874b392037358f Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Mon, 13 Jan 2020 17:47:45 +0100 Subject: [PATCH] add caller to log output --- app/src/main/assets/logback.xml | 4 +-- .../logging/AAPSLoggerProduction.kt | 25 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/assets/logback.xml b/app/src/main/assets/logback.xml index ae1594f639..5329eb18d0 100644 --- a/app/src/main/assets/logback.xml +++ b/app/src/main/assets/logback.xml @@ -18,7 +18,7 @@ 120 - %d{HH:mm:ss.SSS} [%thread] %.-1level/%logger: [%class{0}.%M\(\):%line]: %msg%n + %d{HH:mm:ss.SSS} [%thread] %.-1level/%logger: %msg%n @@ -27,7 +27,7 @@ %logger{0} - [%thread] [%class{0}.%M\(\):%line]: %msg%n + [%thread]: %msg%n diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt index 65425c4e35..eba38c3dc4 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt +++ b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt @@ -9,51 +9,56 @@ import org.slf4j.LoggerFactory class AAPSLoggerProduction : AAPSLogger { override fun debug(message: String) { - LoggerFactory.getLogger(LTag.CORE.tag).debug(message) + LoggerFactory.getLogger(LTag.CORE.tag).debug(stackLogMarker() + message) } override fun debug(enable: Boolean, tag: LTag, message: String) { if (enable && L.isEnabled(tag.tag)) { - LoggerFactory.getLogger(tag.tag).debug(message) + LoggerFactory.getLogger(tag.tag).debug(stackLogMarker() + message) } } override fun debug(tag: LTag, message: String) { if (L.isEnabled(tag.tag)) { - LoggerFactory.getLogger(tag.tag).debug(message) + LoggerFactory.getLogger(tag.tag).debug(stackLogMarker() + message) } } override fun warn(tag: LTag, message: String) { if (L.isEnabled(tag.tag)) { - LoggerFactory.getLogger(tag.tag).warn(message) + LoggerFactory.getLogger(tag.tag).warn(stackLogMarker() + message) } } override fun info(tag: LTag, message: String) { if (L.isEnabled(tag.tag)) { - LoggerFactory.getLogger(tag.tag).info(message) + LoggerFactory.getLogger(tag.tag).info(stackLogMarker() + message) } } override fun error(tag: LTag, message: String) { if (L.isEnabled(tag.tag)) { - LoggerFactory.getLogger(tag.tag).error(message) + LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + message) } } override fun error(message: String) { - LoggerFactory.getLogger(LTag.CORE.tag).error(message) + LoggerFactory.getLogger(LTag.CORE.tag).error(stackLogMarker() + message) } override fun error(message: String, throwable: Throwable) { - LoggerFactory.getLogger(LTag.CORE.tag).error(message, throwable) + LoggerFactory.getLogger(LTag.CORE.tag).error(stackLogMarker() + message, throwable) } override fun error(tag: LTag, message: String, throwable: Throwable) { if (L.isEnabled(tag.tag)) { - LoggerFactory.getLogger(tag.tag).error(message, throwable) + LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + message, throwable) } } -} \ No newline at end of file +} + +fun StackTraceElement.toLogString(): String = "[${this.className}.${this.methodName}():${this.lineNumber}]: " + +/* Needs to be inline. Don't remove even if IDE suggests it. */ +private inline fun stackLogMarker() = Throwable().stackTrace[1].toLogString() \ No newline at end of file