diff --git a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/log/ConsoleLogger.kt b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/log/ConsoleLogger.kt index fc6b9997..06522545 100644 --- a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/log/ConsoleLogger.kt +++ b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/log/ConsoleLogger.kt @@ -1,18 +1,10 @@ package net.dankito.utils.multiplatform.log -import net.dankito.utils.multiplatform.Date -import net.dankito.utils.multiplatform.DateFormatter - open class ConsoleLogger(name: String) : LoggerBase(name) { - companion object { - private val DateFormatter = DateFormatter("HH:mm:ss.SSS") - } - - override fun log(level: LogLevel, message: String) { - println("${DateFormatter.format(Date())} $level $name - $message") + println(createLogOutput(level, message)) } } \ No newline at end of file diff --git a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/log/LoggerBase.kt b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/log/LoggerBase.kt index 614aaa35..a980864d 100644 --- a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/log/LoggerBase.kt +++ b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/log/LoggerBase.kt @@ -1,11 +1,19 @@ package net.dankito.utils.multiplatform.log +import net.dankito.utils.multiplatform.Date +import net.dankito.utils.multiplatform.DateFormatter + abstract class LoggerBase( override val name: String, open var level: LogLevel = LogLevel.Info ) : Logger { + companion object { + private val DateFormatter = DateFormatter("HH:mm:ss.SSS") + } + + abstract fun log(level: LogLevel, message: String) @@ -88,4 +96,9 @@ abstract class LoggerBase( return message // really, there's not String.format() ?! // TODO: add arguments and exception } + + protected open fun createLogOutput(level: LogLevel, message: String): String { + return "${DateFormatter.format(Date())} [$level] $name - $message" + } + } \ No newline at end of file diff --git a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/log/NSLogLogger.kt b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/log/NSLogLogger.kt index 21ea843f..7b146d22 100644 --- a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/log/NSLogLogger.kt +++ b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/log/NSLogLogger.kt @@ -1,19 +1,12 @@ package net.dankito.utils.multiplatform.log -import net.dankito.utils.multiplatform.Date -import net.dankito.utils.multiplatform.DateFormatter import platform.Foundation.NSLog open class NSLogLogger(name: String) : LoggerBase(name) { - companion object { - private val DateFormatter = DateFormatter("HH:mm:ss.SSS") - } - - override fun log(level: LogLevel, message: String) { - NSLog("${DateFormatter.format(Date())} $level $name - $message") + NSLog(createLogOutput(level, message)) } } \ No newline at end of file