diff --git a/maestro-cli/src/main/java/maestro/cli/App.kt b/maestro-cli/src/main/java/maestro/cli/App.kt index 74b328ab15..73db5f04e5 100644 --- a/maestro-cli/src/main/java/maestro/cli/App.kt +++ b/maestro-cli/src/main/java/maestro/cli/App.kt @@ -60,7 +60,6 @@ import kotlin.system.exitProcess ] ) class App { - @CommandLine.Mixin var disableANSIMixin: DisableAnsiMixin? = null @@ -84,6 +83,9 @@ class App { description = ["(Optional) Device ID to run on explicitly, can be a comma separated list of IDs: --device \"Emulator_1,Emulator_2\" "], ) var deviceId: String? = null + + @Option(names = ["--verbose"], description = ["Enable verbose logging"]) + var verbose: Boolean = false } private fun printVersion() { diff --git a/maestro-cli/src/main/java/maestro/cli/command/PrintHierarchyCommand.kt b/maestro-cli/src/main/java/maestro/cli/command/PrintHierarchyCommand.kt index 9999b8c4d3..0adb842397 100644 --- a/maestro-cli/src/main/java/maestro/cli/command/PrintHierarchyCommand.kt +++ b/maestro-cli/src/main/java/maestro/cli/command/PrintHierarchyCommand.kt @@ -24,6 +24,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import maestro.cli.App import maestro.cli.DisableAnsiMixin import maestro.cli.ShowHelpMixin +import maestro.cli.report.TestDebugReporter import maestro.cli.session.MaestroSessionManager import maestro.cli.view.green import maestro.cli.view.yellow @@ -51,6 +52,12 @@ class PrintHierarchyCommand : Runnable { private val parent: App? = null override fun run() { + TestDebugReporter.install( + debugOutputPathAsString = null, + flattenDebugOutput = false, + printToConsole = parent?.verbose == true, + ) + MaestroSessionManager.newSession( host = parent?.host, port = parent?.port, @@ -73,7 +80,5 @@ class PrintHierarchyCommand : Runnable { println(hierarchy) } - - System.err.println("Have you tried running “maestro studio” to visually inspect your app’s UI elements?".green()) } } diff --git a/maestro-cli/src/main/java/maestro/cli/command/RecordCommand.kt b/maestro-cli/src/main/java/maestro/cli/command/RecordCommand.kt index 57772b532f..11ea0879d0 100644 --- a/maestro-cli/src/main/java/maestro/cli/command/RecordCommand.kt +++ b/maestro-cli/src/main/java/maestro/cli/command/RecordCommand.kt @@ -81,7 +81,7 @@ class RecordCommand : Callable { } - TestDebugReporter.install(debugOutputPathAsString = debugOutput) + TestDebugReporter.install(debugOutputPathAsString = debugOutput, printToConsole = parent?.verbose == true) val path = TestDebugReporter.getDebugOutputPath() return MaestroSessionManager.newSession( diff --git a/maestro-cli/src/main/java/maestro/cli/command/StartDeviceCommand.kt b/maestro-cli/src/main/java/maestro/cli/command/StartDeviceCommand.kt index 81b08bc2d6..a1ed0792b4 100644 --- a/maestro-cli/src/main/java/maestro/cli/command/StartDeviceCommand.kt +++ b/maestro-cli/src/main/java/maestro/cli/command/StartDeviceCommand.kt @@ -65,7 +65,7 @@ class StartDeviceCommand : Callable { private var forceCreate: Boolean = false override fun call(): Int { - TestDebugReporter.install(null) + TestDebugReporter.install(null, printToConsole = parent?.verbose == true) if (EnvUtils.isWSL()) { throw CliError("This command is not supported in Windows WSL. You can launch your emulator manually.") diff --git a/maestro-cli/src/main/java/maestro/cli/command/StudioCommand.kt b/maestro-cli/src/main/java/maestro/cli/command/StudioCommand.kt index 61cdc98313..57dd0d1954 100644 --- a/maestro-cli/src/main/java/maestro/cli/command/StudioCommand.kt +++ b/maestro-cli/src/main/java/maestro/cli/command/StudioCommand.kt @@ -50,7 +50,7 @@ class StudioCommand : Callable { throw CliError("--platform option was deprecated. You can remove it to run your test.") } - TestDebugReporter.install(debugOutputPathAsString = debugOutput) + TestDebugReporter.install(debugOutputPathAsString = debugOutput, printToConsole = parent?.verbose == true) MaestroSessionManager.newSession( host = parent?.host, diff --git a/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt b/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt index c53a74b3ea..e0da714194 100644 --- a/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt +++ b/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt @@ -167,7 +167,11 @@ class TestCommand : Callable { env = env.withInjectedShellEnvVars() - TestDebugReporter.install(debugOutputPathAsString = debugOutput, flattenDebugOutput = flattenDebugOutput) + TestDebugReporter.install( + debugOutputPathAsString = debugOutput, + flattenDebugOutput = flattenDebugOutput, + printToConsole = parent?.verbose == true, + ) val debugOutputPath = TestDebugReporter.getDebugOutputPath() return handleSessions(debugOutputPath, executionPlan) @@ -300,7 +304,7 @@ class TestCommand : Callable { } else { val resultView = - if (DisableAnsiMixin.ansiEnabled) AnsiResultView() + if (DisableAnsiMixin.ansiEnabled && parent?.verbose == false) AnsiResultView() else PlainTextResultView() val resultSingle = TestRunner.runSingle( maestro, diff --git a/maestro-cli/src/main/java/maestro/cli/report/TestDebugReporter.kt b/maestro-cli/src/main/java/maestro/cli/report/TestDebugReporter.kt index 9d05ecf576..432b8356fb 100644 --- a/maestro-cli/src/main/java/maestro/cli/report/TestDebugReporter.kt +++ b/maestro-cli/src/main/java/maestro/cli/report/TestDebugReporter.kt @@ -134,11 +134,11 @@ object TestDebugReporter { logger.info("---------------------") } - fun install(debugOutputPathAsString: String?, flattenDebugOutput: Boolean = false) { + fun install(debugOutputPathAsString: String?, flattenDebugOutput: Boolean = false, printToConsole: Boolean) { this.debugOutputPathAsString = debugOutputPathAsString this.flattenDebugOutput = flattenDebugOutput val path = getDebugOutputPath() - LogConfig.configure(path.absolutePathString() + "/maestro.log") + LogConfig.configure(logFileName = path.absolutePathString() + "/maestro.log", printToConsole = printToConsole) logSystemInfo() DebugLogStore.logSystemInfo() } @@ -163,7 +163,6 @@ object TestDebugReporter { val foldername = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss").format(LocalDateTime.now()) return Paths.get(debugRootPath, *preamble, foldername) } - } private data class CommandDebugWrapper( diff --git a/maestro-client/src/main/java/maestro/debuglog/LogConfig.kt b/maestro-client/src/main/java/maestro/debuglog/LogConfig.kt index 354f774e9c..4129f6cce0 100644 --- a/maestro-client/src/main/java/maestro/debuglog/LogConfig.kt +++ b/maestro-client/src/main/java/maestro/debuglog/LogConfig.kt @@ -13,14 +13,16 @@ import java.util.Properties object LogConfig { private const val LOG_PATTERN = "[%-5level] %logger{36} - %msg%n" - fun configure(logFileName: String) { + fun configure(logFileName: String, printToConsole: Boolean) { val loggerContext = LoggerFactory.getILoggerFactory() as LoggerContext loggerContext.statusManager.add(NopStatusListener()) loggerContext.reset() val encoder = createEncoder(loggerContext) -// createAndAddConsoleAppender(loggerContext, encoder) // un-comment to enable console logs createAndAddFileAppender(loggerContext, encoder, logFileName) + if (printToConsole) { + createAndAddConsoleAppender(loggerContext, encoder) + } loggerContext.getLogger("ROOT").level = Level.INFO }