diff --git a/src/main/java/de/bixilon/minosoft/config/config/general/GeneralConfig.kt b/src/main/java/de/bixilon/minosoft/config/config/general/GeneralConfig.kt index 2e741b2c5..a936c597c 100644 --- a/src/main/java/de/bixilon/minosoft/config/config/general/GeneralConfig.kt +++ b/src/main/java/de/bixilon/minosoft/config/config/general/GeneralConfig.kt @@ -15,10 +15,11 @@ package de.bixilon.minosoft.config.config.general import com.squareup.moshi.Json import de.bixilon.minosoft.config.Configuration +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType data class GeneralConfig( var version: Int = Configuration.LATEST_CONFIG_VERSION, - @Json(name = "enabled_log_types") var enabledLogTypes: MutableSet = LogMessageType.DEFAULT_LOG_MESSAGE_TYPES.toMutableSet(), + @Json(name = "log") var log: MutableMap = LogMessageType.DEFAULT_LOG_MAP.toMutableMap(), var language: String = "en_US", ) diff --git a/src/main/java/de/bixilon/minosoft/data/assets/FileAssetsManager.kt b/src/main/java/de/bixilon/minosoft/data/assets/FileAssetsManager.kt index 19c93ea83..e02b94e7f 100644 --- a/src/main/java/de/bixilon/minosoft/data/assets/FileAssetsManager.kt +++ b/src/main/java/de/bixilon/minosoft/data/assets/FileAssetsManager.kt @@ -17,7 +17,8 @@ import de.bixilon.minosoft.Minosoft import de.bixilon.minosoft.config.StaticConfiguration import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.util.Util -import de.bixilon.minosoft.util.logging.Log.log +import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import java.io.* import java.nio.file.Files @@ -58,7 +59,7 @@ interface FileAssetsManager : AssetsManager { hash == Util.sha1(File(getAssetDiskPath(hash))) } } catch (exception: IOException) { - log(LogMessageType.OTHER_DEBUG, message = exception) + Log.log(LogMessageType.ASSETS, level = LogLevels.VERBOSE, message = exception) } return false } @@ -74,7 +75,7 @@ interface FileAssetsManager : AssetsManager { if (checkURL) { Util.checkURL(url) } - log(LogMessageType.OTHER_DEBUG, message = "Downloading %s -> %s", formatting = arrayOf(url, hash)) + Log.log(LogMessageType.ASSETS, level = LogLevels.VERBOSE, message = "Downloading %s -> %s", formatting = arrayOf(url, hash)) if (compress) { Util.downloadFileAsGz(url, getAssetDiskPath(hash)) return diff --git a/src/main/java/de/bixilon/minosoft/data/entities/meta/EntityMetaData.kt b/src/main/java/de/bixilon/minosoft/data/entities/meta/EntityMetaData.kt index 5e70a79f5..a1f7363b4 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/meta/EntityMetaData.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/meta/EntityMetaData.kt @@ -29,7 +29,8 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.util.BitByte import de.bixilon.minosoft.util.KUtil import de.bixilon.minosoft.util.enum.ValuesEnum -import de.bixilon.minosoft.util.logging.Log.log +import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import glm_.vec3.Vec3i import java.util.* @@ -128,7 +129,7 @@ class EntityMetaData( try { return it as K } catch (e: ClassCastException) { - log(LogMessageType.OTHER_DEBUG, message = e) + Log.log(LogMessageType.OTHER, level = LogLevels.WARN, message = e) } } return field.getDefaultValue() diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/versions/Version.kt b/src/main/java/de/bixilon/minosoft/data/mappings/versions/Version.kt index c22297d5e..c17b47bea 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/versions/Version.kt +++ b/src/main/java/de/bixilon/minosoft/data/mappings/versions/Version.kt @@ -24,7 +24,8 @@ import de.bixilon.minosoft.protocol.protocol.PacketTypes.S2C import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.util.CountUpAndDownLatch import de.bixilon.minosoft.util.Util -import de.bixilon.minosoft.util.logging.Log.log +import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType data class Version( @@ -85,7 +86,7 @@ data class Version( } latch.countUp() isGettingLoaded = true - log(LogMessageType.OTHER_DEBUG, message = String.format("Loading mappings for version %s...", this), formatting = arrayOf()) + Log.log(LogMessageType.VERSION_LOADING, level = LogLevels.INFO) { "Loading mappings for $this..." } initializeAssetManger(latch) val startTime = System.currentTimeMillis() @@ -99,7 +100,7 @@ data class Version( Util.readJsonFromStream(assetsManager.readAssetAsStream(Resources.getPixLyzerDataHashByVersion(this))) } catch (exception: Throwable) { // should not happen, but if this version is not flattened, we can fallback to the flatten mappings. Some things might not work... - log(LogMessageType.OTHER_DEBUG, message = exception) + Log.log(LogMessageType.VERSION_LOADING, level = LogLevels.VERBOSE) { exception } if (isFlattened()) { throw exception } @@ -112,9 +113,9 @@ data class Version( mapping.load(this, pixlyzerData) latch.countDown() if (pixlyzerData.size() > 0) { - log(LogMessageType.OTHER_DEBUG, message = String.format("Loaded mappings for version %s in %dms (%s)", this, (System.currentTimeMillis() - startTime), versionName), formatting = arrayOf()) + Log.log(LogMessageType.VERSION_LOADING, level = LogLevels.INFO) { "Loaded mappings for $this (${versionName} in ${System.currentTimeMillis() - startTime}ms" } } else { - log(LogMessageType.OTHER_DEBUG, message = String.format("Could not load mappings for version %s. Some features will be unavailable.", this), formatting = arrayOf()) + Log.log(LogMessageType.VERSION_LOADING, level = LogLevels.WARN) { "Could not load mappings for $this (${versionName}. Some features might not work." } } isLoaded = true isGettingLoaded = false diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt index 5c69ddc98..eab79c91b 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt @@ -37,7 +37,7 @@ import de.bixilon.minosoft.protocol.network.connection.PlayConnection import de.bixilon.minosoft.protocol.packets.s2c.play.PositionAndRotationS2CP import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.util.CountUpAndDownLatch -import de.bixilon.minosoft.util.logging.Log.log +import de.bixilon.minosoft.util.logging.Log import de.bixilon.minosoft.util.logging.LogMessageType import glm_.vec2.Vec2 import glm_.vec2.Vec2i @@ -113,6 +113,7 @@ class RenderWindow( } fun init(latch: CountUpAndDownLatch) { + Log.log(LogMessageType.RENDERING_LOADING) { "Creating window..." } // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set() @@ -164,6 +165,7 @@ class RenderWindow( glfwSetWindowPos(windowId, (videoMode.width() - pWidth[0]) / 2, (videoMode.height() - pHeight[0]) / 2) } + Log.log(LogMessageType.RENDERING_LOADING) { "Creating context..." } // Make the OpenGL context current glfwMakeContextCurrent(windowId) // Enable v-sync @@ -175,6 +177,7 @@ class RenderWindow( setSkyColor(RGBColor("#fffe7a")) + Log.log(LogMessageType.RENDERING_LOADING) { "Enabling all open gl features..." } glEnable(GL_DEPTH_TEST) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) @@ -182,6 +185,7 @@ class RenderWindow( glEnable(GL_CULL_FACE) + Log.log(LogMessageType.RENDERING_LOADING) { "Generating font and textures..." } textures.allTextures.add(Texture(RenderConstants.DEBUG_TEXTURE_RESOURCE_LOCATION)) WHITE_TEXTURE = TextureLikeTexture( texture = Texture(ResourceLocation("minosoft:textures/white.png")), @@ -195,16 +199,20 @@ class RenderWindow( font.preLoadAtlas(textures) + Log.log(LogMessageType.RENDERING_LOADING) { "Initializing renderer..." } for (renderer in rendererMap.values) { renderer.init() } + Log.log(LogMessageType.RENDERING_LOADING) { "Preloading textures..." } textures.preLoad(connection.assetsManager) font.loadAtlas() + Log.log(LogMessageType.RENDERING_LOADING) { "Loading textures..." } textures.load() + Log.log(LogMessageType.RENDERING_LOADING) { "Post loading renderer..." } for (renderer in rendererMap.values) { renderer.postInit() if (renderer is ShaderHolder) { @@ -213,6 +221,7 @@ class RenderWindow( } + Log.log(LogMessageType.RENDERING_LOADING) { "Registering glfw callbacks..." } glfwSetWindowSizeCallback(windowId, object : GLFWWindowSizeCallback() { override fun invoke(window: Long, width: Int, height: Int) { glViewport(0, 0, width, height) @@ -254,11 +263,12 @@ class RenderWindow( glEnable(GL_DEPTH_TEST) - log(LogMessageType.OTHER_DEBUG, message = "Rendering is prepared and ready to go!", formatting = arrayOf()) + Log.log(LogMessageType.RENDERING_LOADING) { "Rendering is fully prepared" } latch.countDown() latch.waitUntilZero() this.latch.waitUntilZero() glfwShowWindow(windowId) + Log.log(LogMessageType.RENDERING_GENERAL) { "Showing window" } } private fun registerGlobalKeyCombinations() { @@ -280,6 +290,7 @@ class RenderWindow( } fun startRenderLoop() { + Log.log(LogMessageType.RENDERING_LOADING) { "Starting loop" } while (!glfwWindowShouldClose(windowId)) { if (renderingState == RenderingStates.PAUSED) { Thread.sleep(100L) @@ -343,6 +354,7 @@ class RenderWindow( } fun exit() { + Log.log(LogMessageType.RENDERING_LOADING) { "Destroying render window..." } // Free the window callbacks and destroy the window Callbacks.glfwFreeCallbacks(windowId) glfwDestroyWindow(windowId) @@ -351,6 +363,7 @@ class RenderWindow( glfwTerminate() glfwSetErrorCallback(null)!!.free() + Log.log(LogMessageType.RENDERING_LOADING) { "Render window destroyed!" } // disconnect connection.disconnect() } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/connection/PlayConnection.kt b/src/main/java/de/bixilon/minosoft/protocol/network/connection/PlayConnection.kt index 146886651..23d9bc0ff 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/connection/PlayConnection.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/connection/PlayConnection.kt @@ -41,7 +41,7 @@ import de.bixilon.minosoft.terminal.commands.commands.Command import de.bixilon.minosoft.util.CountUpAndDownLatch import de.bixilon.minosoft.util.ServerAddress import de.bixilon.minosoft.util.logging.Log -import de.bixilon.minosoft.util.logging.Log.log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import de.bixilon.minosoft.util.time.TimeWorker import de.bixilon.minosoft.util.time.TimeWorkerTask @@ -158,11 +158,11 @@ class PlayConnection( } latch.waitForChange() } - log(LogMessageType.OTHER_INFO, message = "Connecting to server: $address", formatting = arrayOf()) + Log.log(LogMessageType.NETWORK_STATUS, level = LogLevels.INFO) { "Connecting to server: $address" } network.connect(address) } catch (exception: Throwable) { - Log.log(LogMessageType.VERSION_LOADING) { exception } - log(LogMessageType.OTHER_FATAL, message = "Could not load version $version. This version seems to be unsupported!", formatting = arrayOf()) + Log.log(LogMessageType.VERSION_LOADING, level = LogLevels.FATAL) { exception } + Log.log(LogMessageType.VERSION_LOADING, level = LogLevels.FATAL) { "Could not load version $version. This version seems to be unsupported" } version.unload() lastException = MappingsLoadingException("Mappings could not be loaded", exception) connectionState = ConnectionStates.FAILED_NO_RETRY @@ -200,7 +200,7 @@ class PlayConnection( packet.handle(this) } } catch (exception: Throwable) { - Log.log(LogMessageType.NETWORK_PACKETS_IN_ERROR) { exception } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.WARN) { exception } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/connection/StatusConnection.kt b/src/main/java/de/bixilon/minosoft/protocol/network/connection/StatusConnection.kt index 78d35827e..a5f745e4e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/connection/StatusConnection.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/connection/StatusConnection.kt @@ -33,6 +33,7 @@ import de.bixilon.minosoft.protocol.protocol.Protocol import de.bixilon.minosoft.util.DNSUtil import de.bixilon.minosoft.util.ServerAddress import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import java.util.* @@ -142,7 +143,7 @@ class StatusConnection( packet.handle(this) } } catch (exception: Throwable) { - Log.log(LogMessageType.NETWORK_PACKETS_IN_ERROR) { exception } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.WARN) { exception } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/socket/BlockingSocketNetwork.java b/src/main/java/de/bixilon/minosoft/protocol/network/socket/BlockingSocketNetwork.java index 33721cbaf..f33258504 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/socket/BlockingSocketNetwork.java +++ b/src/main/java/de/bixilon/minosoft/protocol/network/socket/BlockingSocketNetwork.java @@ -28,6 +28,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition; import de.bixilon.minosoft.util.Pair; import de.bixilon.minosoft.util.ServerAddress; import de.bixilon.minosoft.util.logging.Log; +import de.bixilon.minosoft.util.logging.LogLevels; import de.bixilon.minosoft.util.logging.LogMessageType; import javax.crypto.Cipher; @@ -107,7 +108,7 @@ public class BlockingSocketNetwork extends Network { var typeAndPacket = prepareS2CPacket(this.inputStream); handlePacket(typeAndPacket.getKey(), typeAndPacket.getValue()); } catch (PacketParseException e) { - Log.printException(e, LogMessageType.NETWORK_PACKETS_IN_ERROR); + Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.WARN, e); } } this.connection.disconnect(); @@ -121,7 +122,7 @@ public class BlockingSocketNetwork extends Network { this.connection.setConnectionState(ConnectionStates.DISCONNECTED); return; } - Log.printException(exception, LogMessageType.NETWORK_PACKETS_IN_ERROR); + Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.WARN, exception); this.connection.setLastException(exception); this.connection.setConnectionState(ConnectionStates.FAILED); } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/socket/NonBlockingSocketNetwork.java b/src/main/java/de/bixilon/minosoft/protocol/network/socket/NonBlockingSocketNetwork.java index 08a8817ae..3a7dea4cf 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/socket/NonBlockingSocketNetwork.java +++ b/src/main/java/de/bixilon/minosoft/protocol/network/socket/NonBlockingSocketNetwork.java @@ -24,6 +24,7 @@ import de.bixilon.minosoft.protocol.protocol.CryptManager; import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition; import de.bixilon.minosoft.util.ServerAddress; import de.bixilon.minosoft.util.logging.Log; +import de.bixilon.minosoft.util.logging.LogLevels; import de.bixilon.minosoft.util.logging.LogMessageType; import javax.crypto.Cipher; @@ -140,7 +141,7 @@ public class NonBlockingSocketNetwork extends Network { var typeAndPacket = receiveS2CPacket(decryptData(currentPacketBuffer.array())); handlePacket(typeAndPacket.getKey(), typeAndPacket.getValue()); } catch (PacketParseException e) { - Log.printException(e, LogMessageType.NETWORK_PACKETS_IN_ERROR); + Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.WARN, e); } currentPacketBuffer.clear(); currentPacketBuffer = null; @@ -159,7 +160,7 @@ public class NonBlockingSocketNetwork extends Network { if (exception instanceof SocketException && exception.getMessage().equals("Socket closed")) { return; } - Log.printException(exception, LogMessageType.NETWORK_PACKETS_IN_ERROR); + Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.WARN, exception); this.connection.setLastException(exception); this.connection.setConnectionState(ConnectionStates.FAILED); } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/c2s/handshaking/HandshakeC2SPacket.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/c2s/handshaking/HandshakeC2SPacket.kt index 4e6dcd2b0..ccc5e080e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/c2s/handshaking/HandshakeC2SPacket.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/c2s/handshaking/HandshakeC2SPacket.kt @@ -34,6 +34,6 @@ class HandshakeC2SPacket( } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_OUT) { "Handshake packet" } + Log.log(LogMessageType.NETWORK_PACKETS_OUT) { "Handshake" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/BlockEntityMetaDataS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/BlockEntityMetaDataS2CP.kt index 70fedc9a1..39c5a1374 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/BlockEntityMetaDataS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/BlockEntityMetaDataS2CP.kt @@ -19,6 +19,7 @@ import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast import glm_.vec3.Vec3i @@ -42,6 +43,6 @@ class BlockEntityMetaDataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Block entity meta data (position=$position, type=$type, nbt=$nbt)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Block entity meta data (position=$position, type=$type, nbt=$nbt)" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/BlockSetS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/BlockSetS2CP.kt index 6355980bb..408e83f88 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/BlockSetS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/BlockSetS2CP.kt @@ -24,6 +24,7 @@ import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import glm_.vec3.Vec3i @@ -61,6 +62,6 @@ class BlockSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Block change (position=${blockPosition}, block=$block)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Block change (position=${blockPosition}, block=$block)" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ChatMessageS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ChatMessageS2CP.kt index 7c4920b52..3f36be757 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ChatMessageS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ChatMessageS2CP.kt @@ -21,6 +21,7 @@ import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import java.util.* @@ -51,10 +52,10 @@ class ChatMessageS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { ChatTextPositions.ABOVE_HOTBAR -> "[HOTBAR] " else -> "" } - Log.log(LogMessageType.CHAT_IN, ChatComponent.valueOf(raw = additionalPrefix)) { event.message } + Log.log(LogMessageType.CHAT_IN, additionalPrefix = ChatComponent.valueOf(raw = additionalPrefix)) { event.message } } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Received chat message (message=\"$message\")" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Received chat message (message=\"$message\")" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ChunkDataS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ChunkDataS2CP.kt index cf12a06d9..a5b103af6 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ChunkDataS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ChunkDataS2CP.kt @@ -27,7 +27,7 @@ import de.bixilon.minosoft.util.KUtil.nullCast import de.bixilon.minosoft.util.Util import de.bixilon.minosoft.util.chunk.ChunkUtil import de.bixilon.minosoft.util.logging.Log -import de.bixilon.minosoft.util.logging.Log.log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast import glm_.vec2.Vec2i @@ -108,7 +108,7 @@ class ChunkDataS2CP() : PlayS2CPacket() { val position = Vec3i(nbt["x"]?.nullCast()!!, nbt["y"]?.nullCast()!!, nbt["z"]?.nullCast()!!) val resourceLocation = ResourceLocation(nbt["id"]?.nullCast()!!) val type = buffer.connection.mapping.blockEntityRegistry.get(resourceLocation) ?: let { - log(LogMessageType.OTHER_ERROR, message = "Unknown block entity $resourceLocation", formatting = arrayOf()) + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.WARN) { "Unknown block entity: $resourceLocation" } null } ?: continue val entity = type.build(buffer.connection) ?: continue @@ -140,6 +140,6 @@ class ChunkDataS2CP() : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Chunk data (chunkPosition=$chunkPosition)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Chunk data (chunkPosition=$chunkPosition)" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ChunkLightDataS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ChunkLightDataS2CP.kt index 7a9425039..153b28118 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ChunkLightDataS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ChunkLightDataS2CP.kt @@ -23,6 +23,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.KUtil import de.bixilon.minosoft.util.chunk.LightUtil.readLightPacket import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import glm_.vec2.Vec2i import java.util.* @@ -57,7 +58,7 @@ class ChunkLightDataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Chunk light data (position=$chunkPosition)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Chunk light data (position=$chunkPosition)" } } override fun handle(connection: PlayConnection) { diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/EntityAnimationS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/EntityAnimationS2CP.kt index 46a1ae9b3..74eac76f2 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/EntityAnimationS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/EntityAnimationS2CP.kt @@ -17,6 +17,7 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.util.KUtil import de.bixilon.minosoft.util.enum.ValuesEnum import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType class EntityAnimationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { @@ -25,7 +26,7 @@ class EntityAnimationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Play entity animation (entityId=$entityId, animation=$animation)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Play entity animation (entityId=$entityId, animation=$animation)" } } enum class EntityAnimations { diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/EntityMetadataS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/EntityMetadataS2CP.kt index 9eb5eb31d..0f113ca5b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/EntityMetadataS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/EntityMetadataS2CP.kt @@ -19,6 +19,7 @@ import de.bixilon.minosoft.protocol.network.connection.PlayConnection import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType class EntityMetadataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { @@ -37,6 +38,6 @@ class EntityMetadataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "[IN] Received entity metadata (entityId=$entityId)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "[IN] Received entity metadata (entityId=$entityId)" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/EntityVelocityS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/EntityVelocityS2CP.kt index 737e95ad8..87de0b6c1 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/EntityVelocityS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/EntityVelocityS2CP.kt @@ -17,6 +17,7 @@ import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import glm_.vec3.Vec3 @@ -30,6 +31,6 @@ class EntityVelocityS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "[IN] Entity velocity changed(entityId=$entityId, velocity=$velocity)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "[IN] Entity velocity changed(entityId=$entityId, velocity=$velocity)" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/HotbarSlotSetS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/HotbarSlotSetS2CP.kt index a4f5e9103..f80606431 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/HotbarSlotSetS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/HotbarSlotSetS2CP.kt @@ -17,6 +17,7 @@ import de.bixilon.minosoft.protocol.network.connection.PlayConnection import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType class HotbarSlotSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { @@ -29,6 +30,6 @@ class HotbarSlotSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Slot change (slot=$slot)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Slot change (slot=$slot)" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/JoinGameS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/JoinGameS2CP.kt index 1c417e222..585fae5dc 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/JoinGameS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/JoinGameS2CP.kt @@ -31,6 +31,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_20W27A import de.bixilon.minosoft.util.BitByte import de.bixilon.minosoft.util.KUtil.nullCast import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast @@ -178,7 +179,7 @@ class JoinGameS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Join game packet (entityId=$entityId, gamemode=$gamemode, dimension=$dimension, difficulty=$difficulty, hardcore=$isHardcore, viewDistance=$viewDistance)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Join game packet (entityId=$entityId, gamemode=$gamemode, dimension=$dimension, difficulty=$difficulty, hardcore=$isHardcore, viewDistance=$viewDistance)" } } companion object : ErrorHandler { diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/MassBlockSetS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/MassBlockSetS2CP.kt index d127ebd90..d52330d45 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/MassBlockSetS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/MassBlockSetS2CP.kt @@ -24,6 +24,7 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import glm_.vec2.Vec2i import glm_.vec3.Vec3i @@ -99,6 +100,6 @@ class MassBlockSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Multi block change (chunkPosition=${chunkPosition}, count=${blocks.size})" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Multi block change (chunkPosition=${chunkPosition}, count=${blocks.size})" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/MassChunkDataS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/MassChunkDataS2CP.kt index 40cdb957d..7d9bd6834 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/MassChunkDataS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/MassChunkDataS2CP.kt @@ -24,6 +24,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.Util import de.bixilon.minosoft.util.chunk.ChunkUtil import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import glm_.vec2.Vec2i import java.util.* @@ -87,6 +88,6 @@ class MassChunkDataS2CP() : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Mass chunk data (chunks=${data.size})" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Mass chunk data (chunks=${data.size})" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/NBTQueryResponseS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/NBTQueryResponseS2CP.kt index 0a13345cf..8ef79559f 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/NBTQueryResponseS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/NBTQueryResponseS2CP.kt @@ -15,6 +15,7 @@ package de.bixilon.minosoft.protocol.packets.s2c.play import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast @@ -23,6 +24,6 @@ class NBTQueryResponseS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { val nbt: Map = buffer.readNBT()?.compoundCast()!! override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "NBT query response (transactionId=$transactionId nbt=$nbt)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "NBT query response (transactionId=$transactionId nbt=$nbt)" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PlayerAbilitiesS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PlayerAbilitiesS2CP.kt index 5ee417478..7d28f6b04 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PlayerAbilitiesS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PlayerAbilitiesS2CP.kt @@ -18,6 +18,7 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.BitByte.isBit import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType class PlayerAbilitiesS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { @@ -45,7 +46,7 @@ class PlayerAbilitiesS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Player abilities: (isInvulnerable=$isInvulnerable, isFlying=$isFlying, canFly=$canFly, canInstantBuild=$canInstantBuild, flyingSpeed=$flyingSpeed, walkingSpeed=$walkingSpeed)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Player abilities: (isInvulnerable=$isInvulnerable, isFlying=$isFlying, canFly=$canFly, canInstantBuild=$canInstantBuild, flyingSpeed=$flyingSpeed, walkingSpeed=$walkingSpeed)" } } override fun handle(connection: PlayConnection) { diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PositionAndRotationS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PositionAndRotationS2CP.kt index f6e4e1e69..1da71e919 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PositionAndRotationS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/PositionAndRotationS2CP.kt @@ -21,6 +21,7 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.BitByte import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import glm_.vec3.Vec3 @@ -81,6 +82,6 @@ class PositionAndRotationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Player position (position=$position, rotation=$rotation, onGround=$isOnGround)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Player position (position=$position, rotation=$rotation, onGround=$isOnGround)" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/RespawnS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/RespawnS2CP.kt index ca327ab0f..cfbdca665 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/RespawnS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/RespawnS2CP.kt @@ -22,6 +22,7 @@ import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast @@ -94,6 +95,6 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Respawn (dimension=$dimension, difficulty=$difficulty, gamemode=$gamemode, levelType=$levelType)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Respawn (dimension=$dimension, difficulty=$difficulty, gamemode=$gamemode, levelType=$levelType)" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ServerDifficultyS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ServerDifficultyS2CP.kt index 2f4c9e7e5..c6f5ddc15 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ServerDifficultyS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ServerDifficultyS2CP.kt @@ -18,6 +18,7 @@ import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType class ServerDifficultyS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { @@ -37,6 +38,6 @@ class ServerDifficultyS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Server difficulty (difficulty=$difficulty, locked=${locked})" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Server difficulty (difficulty=$difficulty, locked=${locked})" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/SetExperienceS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/SetExperienceS2CP.kt index 9b702e5c8..ebc31086d 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/SetExperienceS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/SetExperienceS2CP.kt @@ -18,6 +18,7 @@ import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType class SetExperienceS2CP() : PlayS2CPacket() { @@ -55,6 +56,6 @@ class SetExperienceS2CP() : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Level update (bar=$bar, level=$level, total=$total)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Level update (bar=$bar, level=$level, total=$total)" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/SetSignTextS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/SetSignTextS2CP.kt index a9bb7eb9b..68944de86 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/SetSignTextS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/SetSignTextS2CP.kt @@ -21,6 +21,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.KUtil.unsafeCast import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import glm_.vec3.Vec3i @@ -52,6 +53,6 @@ class SetSignTextS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Sign data (position=$signPosition, lines=$lines" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Sign data (position=$signPosition, lines=$lines" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/SpawnPlayerS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/SpawnPlayerS2CP.kt index 7e4b00969..9aa718b40 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/SpawnPlayerS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/SpawnPlayerS2CP.kt @@ -24,7 +24,7 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.Util import de.bixilon.minosoft.util.logging.Log -import de.bixilon.minosoft.util.logging.Log.log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import glm_.vec3.Vec3 import java.util.* @@ -78,7 +78,7 @@ class SpawnPlayerS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { if (metaData != null) { entity.entityMetaData = metaData if (StaticConfiguration.VERBOSE_ENTITY_META_DATA_LOGGING) { - log(LogMessageType.OTHER_DEBUG, message = String.format("Metadata of entity %s (entityId=%d): %s", entity.toString(), entityId, entity.entityMetaDataAsString), formatting = arrayOf()) + Log.log(LogMessageType.OTHER, level = LogLevels.VERBOSE) { "Players metadata of $entity: ${entity.entityMetaData}" } } } } @@ -91,6 +91,6 @@ class SpawnPlayerS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Player spawned (position=${entity.position}, entityId=$entityId, name=${entity.name}, uuid=$entityUUID)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Player spawned (position=${entity.position}, entityId=$entityId, name=${entity.name}, uuid=$entityUUID)" } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/TabListItemS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/TabListItemS2CP.kt index 3048c60bc..52d83aafd 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/TabListItemS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/TabListItemS2CP.kt @@ -24,6 +24,7 @@ import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import java.nio.charset.StandardCharsets import java.util.* @@ -174,7 +175,7 @@ class TabListItemS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "Received tab list items: $items" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Received tab list items: $items" } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/WorldEventS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/WorldEventS2CP.kt index c62f48b82..a9acb4237 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/WorldEventS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/WorldEventS2CP.kt @@ -16,6 +16,7 @@ import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import glm_.vec3.Vec3i @@ -30,6 +31,6 @@ class WorldEventS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { val isGlobal: Boolean = buffer.readBoolean() override fun log() { - Log.log(LogMessageType.NETWORK_PACKETS_IN) { "World event packet (position=$position, eventId=$eventId, data=$data, isGlobal=$isGlobal)" } + Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "World event packet (position=$position, eventId=$eventId, data=$data, isGlobal=$isGlobal)" } } } diff --git a/src/main/java/de/bixilon/minosoft/util/GitInfo.kt b/src/main/java/de/bixilon/minosoft/util/GitInfo.kt index 47d4b79c6..eaa91f21b 100644 --- a/src/main/java/de/bixilon/minosoft/util/GitInfo.kt +++ b/src/main/java/de/bixilon/minosoft/util/GitInfo.kt @@ -16,7 +16,8 @@ package de.bixilon.minosoft.util import de.bixilon.minosoft.Minosoft import de.bixilon.minosoft.data.mappings.ResourceLocation import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition -import de.bixilon.minosoft.util.logging.Log.log +import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import java.text.DateFormat import java.text.SimpleDateFormat @@ -103,8 +104,8 @@ object GitInfo { IS_INITIALIZED = true } catch (exception: Throwable) { - log(LogMessageType.OTHER_DEBUG, message = exception) - log(LogMessageType.OTHER_ERROR, message = "Can not load git information.", formatting = arrayOf()) + Log.log(LogMessageType.OTHER, level = LogLevels.WARN) { exception } + Log.log(LogMessageType.OTHER, level = LogLevels.WARN) { "Could not load git information." } } } } diff --git a/src/main/java/de/bixilon/minosoft/util/logging/Log.kt b/src/main/java/de/bixilon/minosoft/util/logging/Log.kt index e1ed3d98b..550115489 100644 --- a/src/main/java/de/bixilon/minosoft/util/logging/Log.kt +++ b/src/main/java/de/bixilon/minosoft/util/logging/Log.kt @@ -31,8 +31,8 @@ object Log { private val LOG_QUEUE = LinkedBlockingQueue() private val SYSTEM_ERR_STREAM = System.err private val SYSTEM_OUT_STREAM = System.out - private val ERROR_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER_ERROR) - private val OUT_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER_INFO) + private val ERROR_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER, LogLevels.WARN) + private val OUT_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER, LogLevels.INFO) init { @@ -48,11 +48,12 @@ object Log { message.parts.add(TextComponent("[${TIME_FORMAT.format(messageToSend.time)}] ")) message.parts.add(TextComponent("[${messageToSend.thread.name}] ")) message.parts.add(TextComponent("[${messageToSend.logMessageType}] ")) + message.parts.add(TextComponent("[${messageToSend.level}] ")) messageToSend.additionalPrefix?.let { message.parts.add(it) } message.parts.add(messageToSend.message) - message.applyDefaultColor(messageToSend.logMessageType.color) + message.applyDefaultColor(messageToSend.logMessageType.colorMap[messageToSend.level] ?: messageToSend.logMessageType.defaultColor) val stream = if (messageToSend.logMessageType.error) { SYSTEM_ERR_STREAM @@ -71,9 +72,13 @@ object Log { @DoNotCall @JvmOverloads @JvmStatic - fun log(logMessageType: LogMessageType, additionalPrefix: ChatComponent? = null, message: Any, vararg formatting: Any) { - if (Minosoft.config != null && !Minosoft.config.config.general.enabledLogTypes.contains(logMessageType)) { - return + fun log(logMessageType: LogMessageType, level: LogLevels = LogLevels.INFO, additionalPrefix: ChatComponent? = null, message: Any, vararg formatting: Any) { + if (Minosoft.config != null) { + Minosoft.config.config.general.log[logMessageType]?.let { + if (it.ordinal < level.ordinal) { + return + } + } } val formattedMessage = when (message) { is ChatComponent -> message @@ -91,6 +96,7 @@ object Log { message = formattedMessage, time = System.currentTimeMillis(), logMessageType = logMessageType, + level = level, thread = Thread.currentThread(), additionalPrefix = additionalPrefix, ) @@ -98,11 +104,20 @@ object Log { } @JvmStatic - fun log(logMessageType: LogMessageType, additionalPrefix: ChatComponent? = null, messageBuilder: () -> Any) { - if (!Minosoft.config.config.general.enabledLogTypes.contains(logMessageType)) { - return + fun log(logMessageType: LogMessageType, level: LogLevels = LogLevels.INFO, additionalPrefix: ChatComponent? = null, messageBuilder: () -> Any) { + if (Minosoft.config != null) { + Minosoft.config.config.general.log[logMessageType]?.let { + if (it.ordinal < level.ordinal) { + return + } + } } - log(logMessageType, additionalPrefix, messageBuilder.invoke()) + log(logMessageType, level, additionalPrefix, messageBuilder.invoke()) + } + + @JvmStatic + fun log(logMessageType: LogMessageType, level: LogLevels, messageBuilder: () -> Any) { + log(logMessageType, level = level, additionalPrefix = null, messageBuilder = messageBuilder) } @JvmStatic @@ -110,63 +125,69 @@ object Log { log(logMessageType, additionalPrefix = null, messageBuilder = messageBuilder) } - @Deprecated(message = "Java only", replaceWith = ReplaceWith("log(logMessageType, message = exception)", "de.bixilon.minosoft.util.logging.Log.log")) + @Deprecated(message = "Java only") + @JvmStatic + fun printException(exception: Throwable, logMessageType: LogMessageType, level: LogLevels) { + log(logMessageType, level = level, message = exception) + } + + @Deprecated(message = "Java only") @JvmStatic fun printException(exception: Throwable, logMessageType: LogMessageType) { log(logMessageType, message = exception) } - @Deprecated(message = "Java only", replaceWith = ReplaceWith("log(LogMessageType.OTHER_FATAL, message = message, formatting = formatting)", "de.bixilon.minosoft.util.logging.Log.log")) + @Deprecated(message = "Java only") @JvmStatic fun fatal(message: Any, vararg formatting: Any) { - log(LogMessageType.OTHER_FATAL, message = message, formatting = formatting) + log(LogMessageType.OTHER, level = LogLevels.FATAL, message = message, formatting = formatting) } - @Deprecated(message = "Java only", replaceWith = ReplaceWith("log(LogMessageType.OTHER_ERROR, message = message, formatting = formatting)", "de.bixilon.minosoft.util.logging.Log.log")) + @Deprecated(message = "Java only") @JvmStatic fun error(message: Any, vararg formatting: Any) { - log(LogMessageType.OTHER_ERROR, message = message, formatting = formatting) + log(LogMessageType.OTHER, level = LogLevels.WARN, message = message, formatting = formatting) } - @Deprecated(message = "Java only", replaceWith = ReplaceWith("log(LogMessageType.OTHER_INFO, message = message, formatting = formatting)", "de.bixilon.minosoft.util.logging.Log.log")) + @Deprecated(message = "Java only") @JvmStatic fun info(message: Any, vararg formatting: Any) { - log(LogMessageType.OTHER_INFO, message = message, formatting = formatting) + log(LogMessageType.OTHER, level = LogLevels.INFO, message = message, formatting = formatting) } - @Deprecated(message = "Java only", replaceWith = ReplaceWith("log(LogMessageType.OTHER_DEBUG, message = message, formatting = formatting)", "de.bixilon.minosoft.util.logging.Log.log")) + @Deprecated(message = "Java only") @JvmStatic fun debug(message: Any, vararg formatting: Any) { - log(LogMessageType.OTHER_DEBUG, message = message, formatting = formatting) + log(LogMessageType.OTHER, level = LogLevels.VERBOSE, message = message, formatting = formatting) } - @Deprecated(message = "Java only", replaceWith = ReplaceWith("log(LogMessageType.OTHER_DEBUG, message = message, formatting = formatting)", "de.bixilon.minosoft.util.logging.Log.log")) + @Deprecated(message = "Java only") @JvmStatic fun verbose(message: Any, vararg formatting: Any) { - log(LogMessageType.OTHER_DEBUG, message = message, formatting = formatting) + log(LogMessageType.OTHER, level = LogLevels.VERBOSE, message = message, formatting = formatting) } - @Deprecated(message = "Java only", replaceWith = ReplaceWith("log(LogMessageType.NETWORK_PACKETS_IN, message = message, formatting = formatting)", "de.bixilon.minosoft.util.logging.Log.log")) + @Deprecated(message = "Java only") @JvmStatic fun protocol(message: Any, vararg formatting: Any) { - log(LogMessageType.NETWORK_PACKETS_IN, message = message, formatting = formatting) + log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE, message = message, formatting = formatting) } - @Deprecated(message = "Java only", replaceWith = ReplaceWith("log(LogMessageType.OTHER_ERROR, message = message, formatting = formatting)", "de.bixilon.minosoft.util.logging.Log.log")) + @Deprecated(message = "Java only") @JvmStatic fun warn(message: Any, vararg formatting: Any) { - log(LogMessageType.OTHER_ERROR, message = message, formatting = formatting) + log(LogMessageType.OTHER, level = LogLevels.WARN, message = message, formatting = formatting) } - @Deprecated(message = "Java only", replaceWith = ReplaceWith("log(LogMessageType.OTHER_INFO, message = message, formatting = formatting)", "de.bixilon.minosoft.util.logging.Log.log")) + @Deprecated(message = "Java only") @JvmStatic fun game(message: Any, vararg formatting: Any) { - log(LogMessageType.OTHER_INFO, message = message, formatting = formatting) + log(LogMessageType.OTHER, level = LogLevels.INFO, message = message, formatting = formatting) } - @Deprecated(message = "Java only", replaceWith = ReplaceWith("log(LogMessageType.OTHER_INFO, message = message, formatting = formatting)", "de.bixilon.minosoft.util.logging.Log.log")) + @Deprecated(message = "Java only") @JvmStatic fun mojang(message: Any, vararg formatting: Any) { - log(LogMessageType.OTHER_INFO, message = message, formatting = formatting) + log(LogMessageType.OTHER, level = LogLevels.INFO, message = message, formatting = formatting) } } diff --git a/src/main/java/de/bixilon/minosoft/util/logging/LogLevels.kt b/src/main/java/de/bixilon/minosoft/util/logging/LogLevels.kt new file mode 100644 index 000000000..f9ced7cc9 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/util/logging/LogLevels.kt @@ -0,0 +1,22 @@ +/* + * Minosoft + * Copyright (C) 2021 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.util.logging + +enum class LogLevels { + FATAL, + WARN, + INFO, + VERBOSE, + ; +} diff --git a/src/main/java/de/bixilon/minosoft/util/logging/LogMessageType.kt b/src/main/java/de/bixilon/minosoft/util/logging/LogMessageType.kt index 5567f3c2d..fa6b298fd 100644 --- a/src/main/java/de/bixilon/minosoft/util/logging/LogMessageType.kt +++ b/src/main/java/de/bixilon/minosoft/util/logging/LogMessageType.kt @@ -18,8 +18,9 @@ import de.bixilon.minosoft.util.KUtil import de.bixilon.minosoft.util.enum.ValuesEnum enum class LogMessageType( - val color: RGBColor, - val enabledDefault: Boolean = true, + val defaultColor: RGBColor, + val colorMap: Map = mapOf(), + val defaultLevel: LogLevels = LogLevels.INFO, val error: Boolean = false, ) { GENERAL(ChatColors.WHITE), @@ -27,12 +28,18 @@ enum class LogMessageType( JAVAFX(ChatColors.DARK_GRAY), VERSION_LOADING(ChatColors.YELLOW), + ASSETS(ChatColors.BLACK), NETWORK_RESOLVING(ChatColors.DARK_GREEN), - NETWORK_STATUS(ChatColors.DARK_GREEN, enabledDefault = false), - NETWORK_PACKETS_IN(ChatColors.BLUE, enabledDefault = false), - NETWORK_PACKETS_IN_ERROR(ChatColors.RED, error = true), - NETWORK_PACKETS_OUT(ChatColors.DARK_AQUA, enabledDefault = false), + NETWORK_STATUS(ChatColors.DARK_GREEN), + NETWORK_PACKETS_IN(ChatColors.BLUE, mapOf( + LogLevels.FATAL to ChatColors.DARK_RED, + LogLevels.WARN to ChatColors.RED, + ), defaultLevel = LogLevels.WARN), + NETWORK_PACKETS_OUT(ChatColors.DARK_AQUA, mapOf( + LogLevels.FATAL to ChatColors.DARK_RED, + LogLevels.WARN to ChatColors.RED, + ), defaultLevel = LogLevels.WARN), RENDERING_GENERAL(ChatColors.GREEN), RENDERING_LOADING(ChatColors.GREEN), @@ -40,25 +47,25 @@ enum class LogMessageType( CHAT_IN(ChatColors.LIGHT_PURPLE), CHAT_OUT(ChatColors.LIGHT_PURPLE), - OTHER_INFO(ChatColors.WHITE), - OTHER_DEBUG(ChatColors.YELLOW), - OTHER_ERROR(ChatColors.RED, error = true), - OTHER_FATAL(ChatColors.DARK_RED, error = true), + OTHER(ChatColors.WHITE, mapOf( + LogLevels.FATAL to ChatColors.DARK_RED, + LogLevels.WARN to ChatColors.RED, + LogLevels.VERBOSE to ChatColors.YELLOW, + )), ; companion object : ValuesEnum { override val VALUES: Array = values() override val NAME_MAP: Map = KUtil.getEnumValues(VALUES) - val DEFAULT_LOG_MESSAGE_TYPES = let { - val ret: MutableSet = mutableSetOf() + val DEFAULT_LOG_MAP: Map = let { + val ret: MutableMap = mutableMapOf() for (value in VALUES) { - if (value.enabledDefault) { - ret += value - } + ret[value] = value.defaultLevel } - ret.toSet() + + ret.toMap() } } } diff --git a/src/main/java/de/bixilon/minosoft/util/logging/LogPrintStream.kt b/src/main/java/de/bixilon/minosoft/util/logging/LogPrintStream.kt index 8c54f1159..698996dd9 100644 --- a/src/main/java/de/bixilon/minosoft/util/logging/LogPrintStream.kt +++ b/src/main/java/de/bixilon/minosoft/util/logging/LogPrintStream.kt @@ -14,9 +14,12 @@ package de.bixilon.minosoft.util.logging import java.io.PrintStream -class LogPrintStream(private val level: LogMessageType) : PrintStream(nullOutputStream()) { +class LogPrintStream( + val type: LogMessageType = LogMessageType.OTHER, + val level: LogLevels, +) : PrintStream(nullOutputStream()) { override fun print(string: String) { - Log.log(message = string, logMessageType = level) + Log.log(message = string, logMessageType = type, level = level) } } diff --git a/src/main/java/de/bixilon/minosoft/util/logging/MessageToSend.kt b/src/main/java/de/bixilon/minosoft/util/logging/MessageToSend.kt index ba2ac5e31..1e6e8fdcf 100644 --- a/src/main/java/de/bixilon/minosoft/util/logging/MessageToSend.kt +++ b/src/main/java/de/bixilon/minosoft/util/logging/MessageToSend.kt @@ -19,6 +19,7 @@ data class MessageToSend( val message: ChatComponent, val time: Long, val logMessageType: LogMessageType, + val level: LogLevels, val thread: Thread, val additionalPrefix: ChatComponent? = null, ) diff --git a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAuthentication.java b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAuthentication.java index bad41f9a4..0453dd71e 100644 --- a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAuthentication.java +++ b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAuthentication.java @@ -51,7 +51,7 @@ public final class MojangAuthentication { try { response = HTTP.postJson(ProtocolDefinition.MOJANG_URL_LOGIN, payload); } catch (IOException | InterruptedException e) { - Log.printException(e, LogMessageType.OTHER_INFO); + Log.printException(e, LogMessageType.OTHER); throw new NoNetworkConnectionException(e); } if (response == null) {