diff --git a/src/main/kotlin/app/revanced/cli/logging/impl/DefaultCliLogger.kt b/src/main/kotlin/app/revanced/cli/logging/impl/DefaultCliLogger.kt index a433c4eb..db9306ae 100644 --- a/src/main/kotlin/app/revanced/cli/logging/impl/DefaultCliLogger.kt +++ b/src/main/kotlin/app/revanced/cli/logging/impl/DefaultCliLogger.kt @@ -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") diff --git a/src/main/kotlin/app/revanced/cli/logging/impl/FlushingStreamHandler.kt b/src/main/kotlin/app/revanced/cli/logging/impl/FlushingStreamHandler.kt new file mode 100644 index 00000000..4bfb3941 --- /dev/null +++ b/src/main/kotlin/app/revanced/cli/logging/impl/FlushingStreamHandler.kt @@ -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() + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/cli/patcher/logging/impl/PatcherLogger.kt b/src/main/kotlin/app/revanced/cli/patcher/logging/impl/PatcherLogger.kt index 172fa9b3..11c04a79 100644 --- a/src/main/kotlin/app/revanced/cli/patcher/logging/impl/PatcherLogger.kt +++ b/src/main/kotlin/app/revanced/cli/patcher/logging/impl/PatcherLogger.kt @@ -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)