mirror of
https://github.com/revanced/revanced-cli.git
synced 2024-11-11 06:09:24 +01:00
fix: Log not showing in CLI (#80)
* Fix #79. Changed from default StreamHandler to FlushingStreamHandler which flushes after every log statement * Added removal of handlers, so they will not be duplicated. * Replaced removal of handlers with addition only in case if there are no handlers already. Changed errorLogger name from hardcoded to reusing previous logger name, so it will have the same name if only first parameter is used. * Replaced calls ::javaClass.name to ::class.java.name to have proper class names in loggers
This commit is contained in:
parent
6447311b0a
commit
d9c5a179c5
@ -4,17 +4,19 @@ import app.revanced.cli.command.MainCommand
|
||||
import app.revanced.cli.logging.CliLogger
|
||||
import java.util.logging.Logger
|
||||
import java.util.logging.SimpleFormatter
|
||||
import java.util.logging.StreamHandler
|
||||
|
||||
internal class DefaultCliLogger(
|
||||
private val logger: Logger = Logger.getLogger(MainCommand::javaClass.name),
|
||||
private val errorLogger: Logger = Logger.getLogger(MainCommand::javaClass.name + "Err")
|
||||
private val logger: Logger = Logger.getLogger(MainCommand::class.java.name),
|
||||
private val errorLogger: Logger = Logger.getLogger(logger.name + "Err")
|
||||
) : CliLogger {
|
||||
|
||||
init {
|
||||
logger.useParentHandlers = false
|
||||
logger.addHandler(StreamHandler(System.out, SimpleFormatter()))
|
||||
if (logger.handlers.isEmpty()) {
|
||||
logger.addHandler(FlushingStreamHandler(System.out, SimpleFormatter()))
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
init {
|
||||
System.setProperty("java.util.logging.SimpleFormatter.format", "%4\$s: %5\$s %n")
|
||||
|
@ -0,0 +1,13 @@
|
||||
package app.revanced.cli.logging.impl
|
||||
|
||||
import java.io.OutputStream
|
||||
import java.util.logging.Formatter
|
||||
import java.util.logging.LogRecord
|
||||
import java.util.logging.StreamHandler
|
||||
|
||||
internal class FlushingStreamHandler(out: OutputStream, format: Formatter) : StreamHandler(out, format) {
|
||||
override fun publish(record: LogRecord) {
|
||||
super.publish(record)
|
||||
flush()
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ import app.revanced.cli.logging.impl.DefaultCliLogger
|
||||
import java.util.logging.Logger
|
||||
|
||||
internal object PatcherLogger : app.revanced.patcher.logging.Logger{
|
||||
private val logger = DefaultCliLogger(Logger.getLogger(app.revanced.patcher.Patcher::javaClass.name))
|
||||
private val logger = DefaultCliLogger(Logger.getLogger(app.revanced.patcher.Patcher::class.java.name))
|
||||
|
||||
override fun error(msg: String) = logger.error(msg)
|
||||
override fun info(msg: String) = logger.info(msg)
|
||||
|
Loading…
Reference in New Issue
Block a user