Skip to content

Commit

Permalink
Separate log files according to XDG spec and macOS dir names
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Mar 24, 2024
1 parent 29ae1d2 commit 7fcc96a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class RenderExceptionsHandler {
fun throwException(message: String) {
if (output == null) {
output = File(
"${SkikoProperties.dataPath}/skiko-render-exception-${ProcessHandle.current().pid()}.log"
"${SkikoProperties.logPath}/skiko-render-exception-${ProcessHandle.current().pid()}.log"
)
}
val exception = RenderException(message)
Expand Down
21 changes: 18 additions & 3 deletions skiko/src/jvmMain/kotlin/org/jetbrains/skiko/SkikoProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ object SkikoProperties {
/**
* The path where to store data files.
*
* It is used for extracting the Skiko binaries (if `libraryPath` isn't null) and logging.
*
* TODO: Use $XDG_STATE_HOME (Unix) / ~/Library/Logs (macOS) for logging instead?
* It is used for extracting the Skiko binaries (if `libraryPath` isn't null).
*/
val dataPath: String get() {
return getProperty("skiko.data.path") ?: when (hostOs) {
Expand All @@ -47,6 +45,23 @@ object SkikoProperties {
}
}

/**
* The path where to store log files.
*/
val logPath: String get() {
return getProperty("skiko.data.path") ?: when (hostOs) {
OS.Windows -> "${getenv("LOCALAPPDATA")}/Skiko"
OS.MacOS, OS.Ios -> "${getProperty("user.home")}/Library/Logs/Skiko"
else -> {
var dataHome = getenv("XDG_STATE_HOME")
if (dataHome == null || !dataHome.startsWith('/')) {
dataHome = "${getProperty("user.home")}/.local/state"
}
return "${dataHome}/skiko"
}
}
}

val vsyncEnabled: Boolean get() = getProperty("skiko.vsync.enabled")?.toBoolean() ?: true

/**
Expand Down

0 comments on commit 7fcc96a

Please sign in to comment.