debugging 如何调试打包的多平台合成桌面应用程序(如macOS)?

j5fpnvbx  于 2023-10-24  发布在  Mac
关注(0)|答案(1)|浏览(142)

我写了一个应用程序的多平台组成的桌面平台,我希望它可以运行在Mac,Linux和Windows很好。
它在Intellij IDEA run中运行良好,显然我可以在Intellij Idea中检查日志。但是当我将应用程序打包到dmg并安装在Mac上时,它出错了,比如index should be non-negative显示。我不知道发生了什么,因为我不知道如何调试包应用程序。
是否有任何日志文件被打印并存储在某处?或者是否有任何工具可以调试打包的应用程序,如Android中的adb-tools?

yebdmbv4

yebdmbv41#

  1. Logback可以满足我的要求。设置你的src/commonMain/resources/logback.xml,它可以打印日志到控制台和文件。像这样:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <contextListener class="LoggerStartupListener"/>
    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>${logFilePath}</file>
        <append>true</append>
        <encoder>
            <pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="trace">
        <appender-ref ref="STDOUT"/>
    </root>
    <logger name="io.netty" level="INFO"/>

    <root level="trace">
        <appender-ref ref="FILE"/>
    </root>
    <logger name="io.netty" level="INFO"/>

    <Loggers>
        <Root level="debug">
            <AppenderRef ref="FILE"/>
            <AppenderRef ref="STDOUT"/>
        </Root>
    </Loggers>
</configuration>

LoggerStartupListener在应用程序启动时运行,并为logback.xml提供文件路径值

open class LoggerStartupListener : ContextAwareBase(), LoggerContextListener, LifeCycle {

    private var started = false

    override fun start() {
        val databasePath =
            File(System.getProperty("compose.application.resources.dir"), "passwd_log.log")
        val logFile = File(System.getProperty("compose.application.resources.dir"), "passwd_log.log")
        val context = getContext()
        context.putProperty("logFilePath", logFile.absolutePath)
        println("[LoggerStartupListener] (start) logFilePath: " + logFile.absolutePath)
        started = true
    }

    override fun isStarted(): Boolean {
        return started
    }
}

1.如果你只是想知道在运行从~/Applications/xxx打开的应用程序时发生了什么,你可以right click the app--> open package--> Contents--> MacOS,然后单击xxx,应用程序将通过控制台运行,在控制台上打印日志。

相关问题