mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-04-06 02:01:58 +02:00
Logger test
This commit is contained in:
@@ -69,6 +69,8 @@ dependencies {
|
||||
implementation("com.mayakapps.kache:kache:2.1.1")
|
||||
implementation("io.ktor:ktor-network:3.0.0")
|
||||
implementation("io.ktor:ktor-utils:3.0.3")
|
||||
implementation("io.klogging:klogging:0.11.7")
|
||||
|
||||
|
||||
api("com.github.loucass003:EspflashKotlin:v0.11.0")
|
||||
|
||||
|
||||
26
server/core/src/main/java/dev/slimevr/logger.kt
Normal file
26
server/core/src/main/java/dev/slimevr/logger.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package dev.slimevr
|
||||
|
||||
import io.klogging.Level
|
||||
import io.klogging.config.loggingConfiguration
|
||||
import io.klogging.logger
|
||||
import io.klogging.rendering.RENDER_SIMPLE
|
||||
import io.klogging.sending.STDOUT
|
||||
|
||||
object AppLogger {
|
||||
val tracker = logger("Tracker")
|
||||
val device = logger("Device")
|
||||
val udp = logger("UDPConnection")
|
||||
|
||||
|
||||
init {
|
||||
loggingConfiguration {
|
||||
sink("stdout", RENDER_SIMPLE, STDOUT)
|
||||
logging {
|
||||
fromMinLevel(Level.INFO) {
|
||||
toSink("stdout")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
package dev.slimevr.tracker
|
||||
|
||||
import dev.slimevr.AppLogger
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.context.BasicModule
|
||||
import dev.slimevr.context.Context
|
||||
import dev.slimevr.context.createContext
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
@@ -32,11 +31,13 @@ sealed interface DeviceActions {
|
||||
data class Update(val transform: DeviceState.() -> DeviceState) : DeviceActions
|
||||
}
|
||||
|
||||
|
||||
|
||||
val DeviceStatsModule = DeviceModule(
|
||||
reducer = { s, a -> if (a is DeviceActions.Update) a.transform(s) else s },
|
||||
observer = {
|
||||
it.state.onEach {
|
||||
println("Device state changed $it")
|
||||
it.state.onEach { state ->
|
||||
AppLogger.device.info("Device state changed {State}", state)
|
||||
}.launchIn(it.scope)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.slimevr.tracker
|
||||
|
||||
import dev.slimevr.AppLogger
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.context.BasicModule
|
||||
import dev.slimevr.context.Context
|
||||
@@ -8,7 +9,6 @@ import dev.slimevr.skeleton.BodyPart
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
enum class TrackerStatus(val id: UByte) {
|
||||
@@ -51,10 +51,11 @@ data class Tracker(
|
||||
val context: TrackerContext
|
||||
)
|
||||
|
||||
|
||||
val TrackerInfosModule = TrackerModule(
|
||||
reducer = { s, a -> if (a is TrackerActions.Update) a.transform(s) else s },
|
||||
observer = {
|
||||
it.state.onEach { println("Tracker $it") }.launchIn(it.scope)
|
||||
it.state.onEach { state -> AppLogger.tracker.info("Tracker state changed {State}", state) }.launchIn(it.scope)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.slimevr.tracker.udp
|
||||
|
||||
import dev.slimevr.AppLogger
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.VRServerActions
|
||||
import dev.slimevr.context.Context
|
||||
@@ -64,6 +65,7 @@ data class UDPConnectionModule(
|
||||
val observer: ((UDPConnection) -> Unit)? = null,
|
||||
)
|
||||
|
||||
|
||||
val PacketModule = UDPConnectionModule(
|
||||
reducer = { s, a ->
|
||||
when (a) {
|
||||
@@ -93,10 +95,12 @@ val PacketModule = UDPConnectionModule(
|
||||
time = now
|
||||
)
|
||||
)
|
||||
println("Reconnecting")
|
||||
AppLogger.udp.info("Reconnecting")
|
||||
}
|
||||
} else if (packet.packetNumber < state.lastPacketNum) {
|
||||
println("WARN: Received packet with wrong packet number")
|
||||
it.context.scope.launch {
|
||||
AppLogger.udp.warn("WARN: Received packet with wrong packet number")
|
||||
}
|
||||
return@onAny
|
||||
} else {
|
||||
it.context.scope.launch {
|
||||
@@ -140,7 +144,9 @@ val PingModule = UDPConnectionModule(
|
||||
val deviceId = state.deviceId ?: return@on
|
||||
|
||||
if (paket.data.pingId != state.lastPing.id + 1) {
|
||||
println("Ping ID does not match, ignoring ${paket.data.pingId} != ${state.lastPing.id + 1}")
|
||||
it.context.scope.launch {
|
||||
AppLogger.udp.warn("Ping ID does not match, ignoring ${paket.data.pingId} != ${state.lastPing.id + 1}")
|
||||
}
|
||||
return@on
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
include(":solarxr-protocol")
|
||||
project(":solarxr-protocol").projectDir = File("solarxr-protocol/protocol/java")
|
||||
project(":solarxr-protocol").projectDir = File("solarxr-protocol/protocol/kotlin")
|
||||
|
||||
include(":server")
|
||||
project(":server").projectDir = File("server")
|
||||
|
||||
Submodule solarxr-protocol updated: fa2895b19a...84fc97ff30
Reference in New Issue
Block a user