-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔊 Adding logs to aid diagnostic applications (#17)
- Loading branch information
1 parent
7042d43
commit 35c6bb7
Showing
10 changed files
with
136 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...kotlin/com/clipevery/config/ConfigType.kt → ...n/kotlin/com/clipevery/config/FileType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.clipevery.config | ||
|
||
enum class ConfigType { | ||
enum class FileType { | ||
USER, | ||
SYSTEM | ||
APP, | ||
LOG | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.clipevery.log | ||
|
||
expect fun initLogger(logPath: String) |
17 changes: 10 additions & 7 deletions
17
composeApp/src/commonMain/kotlin/com/clipevery/path/PathProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
package com.clipevery.path | ||
|
||
import com.clipevery.config.ConfigType | ||
import com.clipevery.config.FileType | ||
import java.nio.file.Path | ||
|
||
interface PathProvider { | ||
fun resolve(configName: String, configType: ConfigType): Path { | ||
return when (configType) { | ||
ConfigType.USER -> resolveUser(configName) | ||
ConfigType.SYSTEM -> resolveApp(configName) | ||
fun resolve(fileName: String, fileType: FileType): Path { | ||
return when (fileType) { | ||
FileType.USER -> resolveUser(fileName) | ||
FileType.APP -> resolveApp(fileName) | ||
FileType.LOG -> resolveLog(fileName) | ||
} | ||
} | ||
|
||
fun resolveUser(configName: String): Path | ||
fun resolveUser(fileName: String?): Path | ||
|
||
fun resolveApp(configName: String): Path | ||
fun resolveApp(fileName: String?): Path | ||
|
||
fun resolveLog(fileName: String?): Path | ||
} |
6 changes: 3 additions & 3 deletions
6
composeApp/src/commonMain/kotlin/com/clipevery/presist/FilePersist.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
composeApp/src/desktopMain/kotlin/com/clipevery/log/Logger.desktop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.clipevery.log | ||
|
||
import ch.qos.logback.classic.Level | ||
import ch.qos.logback.classic.LoggerContext | ||
import ch.qos.logback.classic.encoder.PatternLayoutEncoder | ||
import ch.qos.logback.classic.spi.ILoggingEvent | ||
import ch.qos.logback.core.rolling.RollingFileAppender | ||
import ch.qos.logback.core.rolling.TimeBasedRollingPolicy | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
|
||
actual fun initLogger(logPath: String) { | ||
val context = LoggerFactory.getILoggerFactory() as LoggerContext | ||
|
||
val encoder = PatternLayoutEncoder() | ||
encoder.context = context | ||
encoder.pattern = "%date %level [%thread] %logger{10} [%file:%line] %msg%n" | ||
encoder.start() | ||
|
||
val rollingFileAppender = RollingFileAppender<ILoggingEvent>() | ||
rollingFileAppender.context = context | ||
rollingFileAppender.file = logPath | ||
rollingFileAppender.encoder = encoder | ||
|
||
val rollingPolicy = TimeBasedRollingPolicy<ILoggingEvent>() | ||
rollingPolicy.context = context | ||
rollingPolicy.setParent(rollingFileAppender) | ||
rollingPolicy.fileNamePattern = "$logPath.%d{yyyy-MM-dd}.log" | ||
rollingPolicy.maxHistory = 30 | ||
rollingPolicy.start() | ||
|
||
rollingFileAppender.rollingPolicy = rollingPolicy | ||
rollingFileAppender.start() | ||
|
||
val rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME) as ch.qos.logback.classic.Logger | ||
rootLogger.level = Level.DEBUG | ||
rootLogger.addAppender(rollingFileAppender) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters