Hi, does kotlin native (linux/mac/windows) have any good logging library that logs into a file and do rotation like logback/log4j? Most of the multiplatform logging libraries have only console logger by default on native platforms.
s
Shekhar Shinde
05/20/2024, 11:51 AM
Hi @suresh, I had explore to implement the same feature to native for windows but did not found much options.
So I have implemented the file based logger and below is the code for reference.
@OptIn(ExperimentalForeignApi::class)
private fun writeToLogFile(message: String) {
val file = fopen(logFilePath, "a") ?: return // Open the file in append mode
try {
memScoped {
fprintf(file, "%s\n", message.cstr)
}
} finally {
fclose(file)
}
}
Also, please let me know if you found the resolution like log4net for kotlin native.