-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make klogger use java.util.logging.* on the JVM (#1466)
- Loading branch information
Showing
2 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 19 additions & 1 deletion
20
klogger/src/jvmMain/kotlin/com/soywiz/klogger/DefaultLogOutput.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,23 @@ | ||
package com.soywiz.klogger | ||
|
||
import java.util.logging.Level | ||
|
||
actual object DefaultLogOutput : Logger.Output { | ||
override fun output(logger: Logger, level: Logger.Level, msg: Any?) = Logger.ConsoleLogOutput.output(logger, level, msg) | ||
override fun output(logger: Logger, level: Logger.Level, msg: Any?) { | ||
if (logger.nativeLogger == null) { | ||
logger.nativeLogger = java.util.logging.Logger.getLogger(logger.name) | ||
} | ||
//println("logger=$logger, level=$level, msg=$msg") | ||
(logger.nativeLogger as java.util.logging.Logger).log(level.toJava(), msg.toString()) | ||
} | ||
} | ||
|
||
fun Logger.Level.toJava(): Level = when (this) { | ||
Logger.Level.NONE -> Level.OFF | ||
Logger.Level.FATAL -> Level.SEVERE | ||
Logger.Level.ERROR -> Level.SEVERE | ||
Logger.Level.WARN -> Level.WARNING | ||
Logger.Level.INFO -> Level.FINE | ||
Logger.Level.DEBUG -> Level.FINEST | ||
Logger.Level.TRACE -> Level.ALL | ||
} |