Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
fix: Log not showing in CLI (ReVanced#80)
Browse files Browse the repository at this point in the history
* Fix ReVanced#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
  • Loading branch information
EdgE790 authored Jul 11, 2022
1 parent 6447311 commit d9c5a17
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d9c5a17

Please sign in to comment.