Extracted createLogOutput()
This commit is contained in:
parent
da36fafde0
commit
956116bd9f
|
@ -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))
|
||||
}
|
||||
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
|
||||
}
|
|
@ -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))
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue