Extracted createLogOutput()

This commit is contained in:
dankito 2020-07-12 00:30:56 +02:00
parent da36fafde0
commit 956116bd9f
3 changed files with 15 additions and 17 deletions

View File

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

View File

@ -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"
}
}

View File

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