Added persistent logging
This commit is contained in:
parent
cb88826e0a
commit
025f93320a
15 changed files with 72 additions and 35 deletions
|
@ -46,6 +46,10 @@ dependencies {
|
|||
implementation("com.squareup.retrofit2:converter-scalars:2.9.0")
|
||||
implementation("net.i2p.crypto:eddsa:0.3.0")
|
||||
implementation("net.java.dev.jna:jna:5.13.0")
|
||||
implementation("io.github.oshai:kotlin-logging-jvm:4.0.0-beta-27")
|
||||
implementation("org.slf4j:slf4j-api:2.0.7")
|
||||
implementation("org.slf4j:slf4j-reload4j:2.0.7")
|
||||
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.jetpackduba.gitnuro.extensions.preferenceValue
|
|||
import com.jetpackduba.gitnuro.extensions.systemSeparator
|
||||
import com.jetpackduba.gitnuro.extensions.toWindowPlacement
|
||||
import com.jetpackduba.gitnuro.git.AppGpgSigner
|
||||
import com.jetpackduba.gitnuro.logging.printError
|
||||
import com.jetpackduba.gitnuro.logging.printLog
|
||||
import com.jetpackduba.gitnuro.preferences.AppSettings
|
||||
import com.jetpackduba.gitnuro.theme.AppTheme
|
||||
|
@ -82,7 +83,7 @@ class App {
|
|||
appSettings.loadCustomTheme()
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
printLog(TAG, "Failed to load custom theme")
|
||||
printError(TAG, "Failed to load custom theme")
|
||||
ex.printStackTrace()
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.jetpackduba.gitnuro
|
|||
|
||||
import com.jetpackduba.gitnuro.extensions.OS
|
||||
import com.jetpackduba.gitnuro.extensions.getCurrentOs
|
||||
import com.jetpackduba.gitnuro.logging.printError
|
||||
import com.jetpackduba.gitnuro.logging.printLog
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
@ -24,7 +25,7 @@ class AppFilesManager @Inject constructor() {
|
|||
OS.WINDOWS -> System.getenv("APPDATA").orEmpty()
|
||||
OS.MAC -> System.getProperty("user.home") + "/Library/Application"
|
||||
else -> {
|
||||
printLog(TAG, "Unknown OS")
|
||||
printError(TAG, "Unknown OS")
|
||||
throw Exception("Invalid OS")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ class ErrorsManager @Inject constructor() {
|
|||
}
|
||||
|
||||
_error.emit(error)
|
||||
println("LastError flow: $error")
|
||||
}
|
||||
|
||||
fun removeError(error: Error) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.jetpackduba.gitnuro.extensions
|
||||
|
||||
import com.jetpackduba.gitnuro.logging.printError
|
||||
import com.jetpackduba.gitnuro.logging.printLog
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
@ -48,7 +49,7 @@ fun runCommandWithoutResult(command: String, args: String, file: String): Boolea
|
|||
printLog(TAG, "Process ended immediately.")
|
||||
false
|
||||
} else {
|
||||
printLog(TAG, "Process crashed.")
|
||||
printError(TAG, "Process crashed.")
|
||||
false
|
||||
}
|
||||
} catch (itse: IllegalThreadStateException) {
|
||||
|
@ -56,7 +57,7 @@ fun runCommandWithoutResult(command: String, args: String, file: String): Boolea
|
|||
true
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
printLog(TAG, "Error running command: ${e.message}")
|
||||
printError(TAG, "Error running command: ${e.message}", e)
|
||||
e.printStackTrace()
|
||||
false
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.jetpackduba.gitnuro.extensions
|
||||
|
||||
import com.jetpackduba.gitnuro.logging.printError
|
||||
import com.jetpackduba.gitnuro.logging.printLog
|
||||
import java.awt.Desktop
|
||||
import java.io.File
|
||||
|
@ -37,7 +38,7 @@ private fun openSystemSpecific(url: String): Boolean {
|
|||
|
||||
OS.WINDOWS -> if (runCommandWithoutResult("explorer", "%s", url)) return true
|
||||
OS.MAC -> if (runCommandWithoutResult("open", "%s", url)) return true
|
||||
else -> printLog(TAG, "Unknown OS")
|
||||
else -> printError(TAG, "Unknown OS")
|
||||
}
|
||||
|
||||
return false
|
||||
|
@ -48,7 +49,7 @@ private fun openUrlInBrowserJdk(url: String) {
|
|||
try {
|
||||
Desktop.getDesktop().browse(URI(url))
|
||||
} catch (ex: Exception) {
|
||||
println("Failed to open URL in browser")
|
||||
printError(TAG, "Failed to open URL in browser")
|
||||
ex.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +58,7 @@ private fun openFileJdk(filePath: String) {
|
|||
try {
|
||||
Desktop.getDesktop().open(File(filePath))
|
||||
} catch (ex: Exception) {
|
||||
println("Failed to open URL in browser")
|
||||
printError(TAG, "Failed to open URL in browser")
|
||||
ex.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
package com.jetpackduba.gitnuro.logging
|
||||
|
||||
import io.github.oshai.KotlinLogging
|
||||
|
||||
val logger = KotlinLogging.logger("org.slf4j")
|
||||
|
||||
fun printLog(tag: String, message: String) {
|
||||
println("$tag - $message")
|
||||
logger.info("$tag - $message")
|
||||
}
|
||||
fun printDebug(tag: String, message: String) {
|
||||
logger.debug("$tag - $message")
|
||||
}
|
||||
|
||||
fun printError(tag: String, message: String, e: Exception? = null) {
|
||||
logger.error("$tag - $message", e)
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
package com.jetpackduba.gitnuro
|
||||
|
||||
import io.github.oshai.KotlinLogging
|
||||
import java.util.logging.Logger
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val app = App()
|
||||
app.start(args)
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package com.jetpackduba.gitnuro.ssh.libssh
|
||||
|
||||
import com.jetpackduba.gitnuro.logging.printError
|
||||
import com.jetpackduba.gitnuro.ssh.libssh.streams.checkValidResult
|
||||
import javax.inject.Inject
|
||||
|
||||
private const val TAG = "LibSshSession"
|
||||
|
||||
class LibSshSession @Inject constructor() {
|
||||
private val sshLib = SSHLibrary.INSTANCE
|
||||
|
||||
|
@ -25,7 +28,7 @@ class LibSshSession @Inject constructor() {
|
|||
val result = sshLib.ssh_userauth_publickey_auto(session, username, password)
|
||||
|
||||
if (result != 0)
|
||||
println("RESULT is $result. ERROR IS: ${getError()}")
|
||||
printError(TAG, "Result is: $result.\nError is: ${getError()}")
|
||||
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -1,25 +1,26 @@
|
|||
package com.jetpackduba.gitnuro.ssh.libssh.streams
|
||||
|
||||
import com.jetpackduba.gitnuro.logging.printLog
|
||||
import com.jetpackduba.gitnuro.ssh.libssh.SSHLibrary
|
||||
import com.jetpackduba.gitnuro.ssh.libssh.ssh_channel
|
||||
import java.io.InputStream
|
||||
|
||||
private const val TAG = "LibSshChannelInputErrSt"
|
||||
|
||||
class LibSshChannelInputErrStream(private val sshChannel: ssh_channel) : InputStream() {
|
||||
private var cancelled = false
|
||||
private val sshLib = SSHLibrary.INSTANCE
|
||||
|
||||
override fun read(): Int {
|
||||
println("Read error")
|
||||
printLog(TAG, "Read error")
|
||||
val buffer = ByteArray(1)
|
||||
|
||||
return if (sshLib.ssh_channel_poll(sshChannel, 1) > 0) {
|
||||
sshLib.ssh_channel_read(sshChannel, buffer, 1, 1)
|
||||
|
||||
val first = buffer.first()
|
||||
println("Read error finished ${first.toInt()}")
|
||||
|
||||
print(String(buffer))
|
||||
printLog(TAG, "Read error finished ${first.toInt()} - ${String(buffer)}")
|
||||
|
||||
first.toInt()
|
||||
} else
|
||||
|
|
|
@ -31,6 +31,6 @@ class LibSshChannelInputStream(private val sshChannel: ssh_channel) : InputStrea
|
|||
}
|
||||
|
||||
override fun close() {
|
||||
println("Closing input")
|
||||
// The channel is closed by [LibSshChannel]
|
||||
}
|
||||
}
|
|
@ -1,41 +1,37 @@
|
|||
package com.jetpackduba.gitnuro.ssh.libssh.streams
|
||||
|
||||
import com.jetpackduba.gitnuro.logging.printDebug
|
||||
import com.jetpackduba.gitnuro.logging.printLog
|
||||
import com.jetpackduba.gitnuro.ssh.libssh.SSHLibrary
|
||||
import com.jetpackduba.gitnuro.ssh.libssh.ssh_channel
|
||||
import java.io.OutputStream
|
||||
|
||||
private const val TAG = "LibSshChannelOutputStre"
|
||||
|
||||
class LibSshChannelOutputStream(private val sshChannel: ssh_channel) : OutputStream() {
|
||||
private val sshLib = SSHLibrary.INSTANCE
|
||||
|
||||
override fun write(b: Int) {
|
||||
println("write int")
|
||||
printLog(TAG, "Write int")
|
||||
|
||||
val byteArrayData = byteArrayOf(b.toByte())
|
||||
write(byteArrayData)
|
||||
|
||||
println("write int finished")
|
||||
printLog(TAG, "Write int")
|
||||
}
|
||||
|
||||
override fun write(b: ByteArray) {
|
||||
println("write byte")
|
||||
printLog(TAG, "Write byte")
|
||||
sshLib.ssh_channel_write(sshChannel, b, b.size)
|
||||
println("write byte finished")
|
||||
printLog(TAG, "Write byte finished")
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
println("Closing output")
|
||||
printDebug(TAG, "Closing output")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun checkValidResult(result: Int) {
|
||||
if (result != 0)
|
||||
throw Exception("Result is $result")
|
||||
}
|
||||
|
||||
fun checkValidResult(result: Int, callback: (Int) -> Unit) {
|
||||
if (result != 0) {
|
||||
callback(result)
|
||||
throw Exception("Result is $result")
|
||||
}
|
||||
}
|
|
@ -23,7 +23,6 @@ import androidx.compose.ui.window.Popup
|
|||
import androidx.compose.ui.window.PopupPositionProvider
|
||||
import com.jetpackduba.gitnuro.extensions.awaitFirstDownEvent
|
||||
import com.jetpackduba.gitnuro.extensions.handMouseClickable
|
||||
import com.jetpackduba.gitnuro.extensions.handOnHover
|
||||
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
|
||||
import com.jetpackduba.gitnuro.keybindings.matchesBinding
|
||||
import com.jetpackduba.gitnuro.theme.onBackgroundSecondary
|
||||
|
@ -31,7 +30,7 @@ import java.awt.event.MouseEvent
|
|||
import kotlin.math.abs
|
||||
|
||||
private var lastCheck: Long = 0
|
||||
private const val MIN_TIME_BETWEEN_POPUPS = 20
|
||||
private const val MIN_TIME_BETWEEN_POPUPS_IN_MS = 20
|
||||
|
||||
@Composable
|
||||
fun ContextMenu(items: () -> List<ContextMenuElement>, function: @Composable () -> Unit) {
|
||||
|
@ -60,8 +59,8 @@ private fun Modifier.contextMenu(items: () -> List<ContextMenuElement>): Modifie
|
|||
if (mouseEvent != null) {
|
||||
if (lastMouseEvent.button.isSecondary) {
|
||||
val currentCheck = System.currentTimeMillis()
|
||||
if (lastCheck != 0L && currentCheck - lastCheck < MIN_TIME_BETWEEN_POPUPS) {
|
||||
println("IGNORE POPUP TRIGGERED!")
|
||||
if (lastCheck != 0L && currentCheck - lastCheck < MIN_TIME_BETWEEN_POPUPS_IN_MS) {
|
||||
println("Popup ignored!")
|
||||
} else {
|
||||
lastCheck = currentCheck
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.jetpackduba.gitnuro.git.repository.OpenRepositoryUseCase
|
|||
import com.jetpackduba.gitnuro.git.repository.OpenSubmoduleRepositoryUseCase
|
||||
import com.jetpackduba.gitnuro.git.stash.StashChangesUseCase
|
||||
import com.jetpackduba.gitnuro.git.workspace.StageUntrackedFileUseCase
|
||||
import com.jetpackduba.gitnuro.logging.printDebug
|
||||
import com.jetpackduba.gitnuro.logging.printLog
|
||||
import com.jetpackduba.gitnuro.models.AuthorInfoSimple
|
||||
import com.jetpackduba.gitnuro.newErrorNow
|
||||
|
@ -262,11 +263,11 @@ class TabViewModel @Inject constructor(
|
|||
// operation may be running
|
||||
if (diffTime > MIN_TIME_IN_MS_BETWEEN_REFRESHES && !hasGitDirChanged) {
|
||||
updateApp(false)
|
||||
printLog(TAG, "Sync emit with diff time $diffTime")
|
||||
printDebug(TAG, "Sync emit with diff time $diffTime")
|
||||
} else {
|
||||
asyncJob = async {
|
||||
delay(MIN_TIME_IN_MS_BETWEEN_REFRESHES)
|
||||
printLog(TAG, "Async emit")
|
||||
printDebug(TAG, "Async emit")
|
||||
if (isActive)
|
||||
updateApp(hasGitDirChanged)
|
||||
|
||||
|
@ -286,11 +287,11 @@ class TabViewModel @Inject constructor(
|
|||
|
||||
suspend fun updateApp(hasGitDirChanged: Boolean) {
|
||||
if (hasGitDirChanged) {
|
||||
printLog(TAG, "Changes detected in git directory, full refresh")
|
||||
printDebug(TAG, "Changes detected in git directory, full refresh")
|
||||
|
||||
refreshRepositoryInfo()
|
||||
} else {
|
||||
printLog(TAG, "Changes detected, partial refresh")
|
||||
printDebug(TAG, "Changes detected, partial refresh")
|
||||
|
||||
checkUncommitedChanges()
|
||||
}
|
||||
|
|
16
src/main/resources/log4j.properties
Normal file
16
src/main/resources/log4j.properties
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Root logger option
|
||||
log4j.rootLogger=INFO, file, stdout
|
||||
|
||||
# Direct log messages to a log file
|
||||
log4j.appender.file=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.file.File=${user.home}/.gitnuro/gitnuro.log
|
||||
log4j.appender.file.MaxFileSize=10MB
|
||||
log4j.appender.file.MaxBackupIndex=10
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
||||
|
||||
# Direct log messages to stdout
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
Loading…
Reference in a new issue