Fixing MacOS build issue. Improving documentation.
This commit is contained in:
parent
033febece6
commit
0ea2067e42
4 changed files with 65 additions and 31 deletions
|
|
@ -12,7 +12,12 @@ import java.io.File
|
|||
|
||||
object LoggingSetup {
|
||||
|
||||
private var initialized = false
|
||||
|
||||
fun init() {
|
||||
if (initialized) return
|
||||
initialized = true
|
||||
|
||||
val logDir = AppDirectories.logsDir
|
||||
val logFile = File(logDir, "wowbackup.log")
|
||||
|
||||
|
|
@ -26,7 +31,7 @@ object LoggingSetup {
|
|||
|
||||
val rollingPolicy = SizeAndTimeBasedRollingPolicy<ILoggingEvent>().apply {
|
||||
this.context = context
|
||||
fileNamePattern = "${logDir}/wowbackup.%d{yyyy-MM-dd}.%i.log.gz"
|
||||
fileNamePattern = "${logDir.absolutePath}/wowbackup.%d{yyyy-MM-dd}.%i.log.gz"
|
||||
setMaxFileSize(FileSize.valueOf("10MB"))
|
||||
maxHistory = 30
|
||||
setTotalSizeCap(FileSize.valueOf("100MB"))
|
||||
|
|
@ -46,5 +51,10 @@ object LoggingSetup {
|
|||
|
||||
val rootLogger = context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME)
|
||||
rootLogger.addAppender(fileAppender)
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
|
||||
val uncaughtLogger = LoggerFactory.getLogger("UncaughtExceptionHandler")
|
||||
uncaughtLogger.error("Uncaught exception on thread [${thread.name}]", throwable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
package com.rukira.wowbackup.logging
|
||||
|
||||
import com.rukira.wowbackup.platform.AppDirectories
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import java.io.File
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class LoggingSetupTest {
|
||||
|
||||
private val testLogger = KotlinLogging.logger {}
|
||||
|
||||
@Test
|
||||
fun testLoggingSetupInitializesAndWritesToFile() {
|
||||
LoggingSetup.init()
|
||||
|
||||
val logsDir = AppDirectories.logsDir
|
||||
assertTrue(logsDir.exists(), "Logs directory should exist")
|
||||
assertTrue(logsDir.isDirectory, "Logs directory should be a directory")
|
||||
|
||||
val testMessage = "Test log entry for unit verification - ${System.currentTimeMillis()}"
|
||||
testLogger.info { testMessage }
|
||||
|
||||
val logFile = File(logsDir, "wowbackup.log")
|
||||
assertTrue(logFile.exists(), "wowbackup.log file should exist")
|
||||
|
||||
val content = logFile.readText()
|
||||
assertTrue(content.contains(testMessage), "wowbackup.log should contain the logged message")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAppDirectoriesLogsDir() {
|
||||
val appDataDir = AppDirectories.appDataDir
|
||||
val logsDir = AppDirectories.logsDir
|
||||
|
||||
assertTrue(logsDir.absolutePath.startsWith(appDataDir.absolutePath), "Logs dir should be inside app data dir")
|
||||
assertTrue(logsDir.name == "logs", "Logs directory should be named 'logs'")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue