Skip to content

Commit

Permalink
🔊 Set the log level for development debugging to info (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang authored Jan 30, 2024
1 parent cdef40d commit 219c036
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 56 deletions.
2 changes: 2 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ compose.desktop {
application {
mainClass = "com.clipevery.MainKt"

args("info")

nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
modules("jdk.charsets")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.clipevery.log

expect fun initLogger(logPath: String)
expect fun initLogger(logPath: String, logLevel: String)
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import com.clipevery.net.DesktopClipBonjourService
import com.clipevery.net.DesktopClipClient
import com.clipevery.net.DesktopClipServer
import com.clipevery.path.getPathProvider
import com.clipevery.presist.DesktopFilePersist
import com.clipevery.presist.FilePersist
import com.clipevery.presist.getFilePersist
import com.clipevery.realm.RealmManager
import com.clipevery.signal.DesktopPreKeyStore
import com.clipevery.signal.DesktopSessionStore
Expand Down Expand Up @@ -58,7 +58,7 @@ object Dependencies {
// simple component
single<AppInfo> { DesktopAppInfoFactory(get()).createAppInfo() }
single<EndpointInfoFactory> { DesktopEndpointInfoFactory( lazy { get<ClipServer>() }) }
single<FilePersist> { DesktopFilePersist() }
single<FilePersist> { getFilePersist() }
single<ConfigManager> { DefaultConfigManager(get<FilePersist>().getPersist("appConfig.json", AppFileType.USER)) }
single<QRCodeGenerator> { DesktopQRCodeGenerator(get(), get()) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ch.qos.logback.core.rolling.TimeBasedRollingPolicy
import org.slf4j.Logger
import org.slf4j.LoggerFactory

actual fun initLogger(logPath: String) {
actual fun initLogger(logPath: String, logLevel: String) {
val context = LoggerFactory.getILoggerFactory() as LoggerContext

val encoder = PatternLayoutEncoder()
Expand All @@ -33,9 +33,20 @@ actual fun initLogger(logPath: String) {
rollingFileAppender.start()

val rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME) as ch.qos.logback.classic.Logger
rootLogger.level = Level.DEBUG
rootLogger.level = getLevel(logLevel)
rootLogger.addAppender(rollingFileAppender)

val jThemeLogger = context.getLogger("com.jthemedetecor") as ch.qos.logback.classic.Logger
jThemeLogger.level = Level.OFF
}

fun getLevel(logLevel: String): Level {
return when (logLevel) {
"trace" -> Level.TRACE
"debug" -> Level.DEBUG
"info" -> Level.INFO
"warn" -> Level.WARN
"error" -> Level.ERROR
else -> Level.INFO
}
}
113 changes: 62 additions & 51 deletions composeApp/src/desktopMain/kotlin/com/clipevery/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,70 +44,81 @@ fun exitClipEveryApplication(exitApplication: () -> Unit) {
exitApplication()
}

fun main() = application {
fun main(args: Array<String>) {
val logLevel = if (args.isNotEmpty()) {
args[0]
} else {
"info"
}
val pathProvider = getPathProvider()
initLogger(pathProvider.resolve("clipevery.log", AppFileType.LOG).pathString)
initLogger(pathProvider.resolve("clipevery.log", AppFileType.LOG).pathString, logLevel)
val logger = KotlinLogging.logger {}

logger.info { "Starting Clipevery" }

val ioScope = rememberCoroutineScope { ioDispatcher }

val koinApplication = Dependencies.koinApplication

initInject(koinApplication)

val appUI = koinApplication.koin.get<AppUI>()
application {
val ioScope = rememberCoroutineScope { ioDispatcher }

val trayIcon = if(currentPlatform().isMacos()) {
painterResource("clipevery_mac_tray.png")
} else {
painterResource("clipevery_icon.png")
}
val appUI = koinApplication.koin.get<AppUI>()

val windowState = rememberWindowState(
placement = WindowPlacement.Floating,
position = WindowPosition.PlatformDefault,
size = getPreferredWindowSize(appUI)
)

Tray(
icon = trayIcon,
mouseListener = getTrayMouseAdapter(windowState) { appUI.showWindow = !appUI.showWindow },
)

val exitApplication: () -> Unit = {
appUI.showWindow = false
ioScope.launch {
exitClipEveryApplication { exitApplication() }
val trayIcon = if (currentPlatform().isMacos()) {
painterResource("clipevery_mac_tray.png")
} else {
painterResource("clipevery_icon.png")
}

val windowState = rememberWindowState(
placement = WindowPlacement.Floating,
position = WindowPosition.PlatformDefault,
size = getPreferredWindowSize(appUI)
)

Tray(
icon = trayIcon,
mouseListener = getTrayMouseAdapter(windowState) {
appUI.showWindow = !appUI.showWindow
},
)

val exitApplication: () -> Unit = {
appUI.showWindow = false
ioScope.launch {
exitClipEveryApplication { exitApplication() }
}
}
}

Window(
onCloseRequest = exitApplication,
visible = appUI.showWindow,
state = windowState,
title = "Clipevery",
icon = painterResource("clipevery_icon.png"),
alwaysOnTop = true,
undecorated = true,
transparent = true,
resizable = false
) {

LaunchedEffect(Unit) {
window.addWindowFocusListener(object : java.awt.event.WindowFocusListener {
override fun windowGainedFocus(e: java.awt.event.WindowEvent?) {
appUI.showWindow = true
}

override fun windowLostFocus(e: java.awt.event.WindowEvent?) {
appUI.showWindow = false
}
})
Window(
onCloseRequest = exitApplication,
visible = appUI.showWindow,
state = windowState,
title = "Clipevery",
icon = painterResource("clipevery_icon.png"),
alwaysOnTop = true,
undecorated = true,
transparent = true,
resizable = false
) {

LaunchedEffect(Unit) {
window.addWindowFocusListener(object : java.awt.event.WindowFocusListener {
override fun windowGainedFocus(e: java.awt.event.WindowEvent?) {
appUI.showWindow = true
}

override fun windowLostFocus(e: java.awt.event.WindowEvent?) {
appUI.showWindow = false
}
})
}
ClipeveryApp(
koinApplication,
hideWindow = { appUI.showWindow = false },
exitApplication = exitApplication
)
}
ClipeveryApp(koinApplication,
hideWindow = { appUI.showWindow = false },
exitApplication = exitApplication)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import com.clipevery.path.PathProvider
import com.clipevery.path.getPathProvider
import java.nio.file.Path

fun getFilePersist(): FilePersist {
return DesktopFilePersist()
}

class DesktopFilePersist: FilePersist {

override val pathProvider: PathProvider = getPathProvider()
Expand Down

0 comments on commit 219c036

Please sign in to comment.