add caller to log output

This commit is contained in:
AdrianLxM 2020-01-13 17:47:45 +01:00
parent faaa659b3d
commit 70c83c17e0
2 changed files with 17 additions and 12 deletions

View file

@ -18,7 +18,7 @@
<maxHistory>120</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %.-1level/%logger: [%class{0}.%M\(\):%line]: %msg%n</pattern>
<pattern>%d{HH:mm:ss.SSS} [%thread] %.-1level/%logger: %msg%n</pattern>
</encoder>
</appender>
@ -27,7 +27,7 @@
<pattern>%logger{0}</pattern>
</tagEncoder>
<encoder>
<pattern>[%thread] [%class{0}.%M\(\):%line]: %msg%n</pattern>
<pattern>[%thread]: %msg%n</pattern>
</encoder>
</appender>

View file

@ -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)
}
}
}
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()