more log level refactoring

This commit is contained in:
Bixilon 2021-04-25 16:06:34 +02:00
parent 06f21f6de8
commit 52d285cb65
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
39 changed files with 197 additions and 102 deletions

View File

@ -15,10 +15,11 @@ package de.bixilon.minosoft.config.config.general
import com.squareup.moshi.Json import com.squareup.moshi.Json
import de.bixilon.minosoft.config.Configuration import de.bixilon.minosoft.config.Configuration
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType import de.bixilon.minosoft.util.logging.LogMessageType
data class GeneralConfig( data class GeneralConfig(
var version: Int = Configuration.LATEST_CONFIG_VERSION, var version: Int = Configuration.LATEST_CONFIG_VERSION,
@Json(name = "enabled_log_types") var enabledLogTypes: MutableSet<LogMessageType> = LogMessageType.DEFAULT_LOG_MESSAGE_TYPES.toMutableSet(), @Json(name = "log") var log: MutableMap<LogMessageType, LogLevels> = LogMessageType.DEFAULT_LOG_MAP.toMutableMap(),
var language: String = "en_US", var language: String = "en_US",
) )

View File

@ -17,7 +17,8 @@ import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.StaticConfiguration import de.bixilon.minosoft.config.StaticConfiguration
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.Util 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 de.bixilon.minosoft.util.logging.LogMessageType
import java.io.* import java.io.*
import java.nio.file.Files import java.nio.file.Files
@ -58,7 +59,7 @@ interface FileAssetsManager : AssetsManager {
hash == Util.sha1(File(getAssetDiskPath(hash))) hash == Util.sha1(File(getAssetDiskPath(hash)))
} }
} catch (exception: IOException) { } catch (exception: IOException) {
log(LogMessageType.OTHER_DEBUG, message = exception) Log.log(LogMessageType.ASSETS, level = LogLevels.VERBOSE, message = exception)
} }
return false return false
} }
@ -74,7 +75,7 @@ interface FileAssetsManager : AssetsManager {
if (checkURL) { if (checkURL) {
Util.checkURL(url) Util.checkURL(url)
} }
log(LogMessageType.OTHER_DEBUG, message = "Downloading %s -> %s", formatting = arrayOf<Any>(url, hash)) Log.log(LogMessageType.ASSETS, level = LogLevels.VERBOSE, message = "Downloading %s -> %s", formatting = arrayOf<Any>(url, hash))
if (compress) { if (compress) {
Util.downloadFileAsGz(url, getAssetDiskPath(hash)) Util.downloadFileAsGz(url, getAssetDiskPath(hash))
return return

View File

@ -29,7 +29,8 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.util.BitByte import de.bixilon.minosoft.util.BitByte
import de.bixilon.minosoft.util.KUtil import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.enum.ValuesEnum 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 de.bixilon.minosoft.util.logging.LogMessageType
import glm_.vec3.Vec3i import glm_.vec3.Vec3i
import java.util.* import java.util.*
@ -128,7 +129,7 @@ class EntityMetaData(
try { try {
return it as K return it as K
} catch (e: ClassCastException) { } catch (e: ClassCastException) {
log(LogMessageType.OTHER_DEBUG, message = e) Log.log(LogMessageType.OTHER, level = LogLevels.WARN, message = e)
} }
} }
return field.getDefaultValue() return field.getDefaultValue()

View File

@ -24,7 +24,8 @@ import de.bixilon.minosoft.protocol.protocol.PacketTypes.S2C
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.CountUpAndDownLatch import de.bixilon.minosoft.util.CountUpAndDownLatch
import de.bixilon.minosoft.util.Util 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 de.bixilon.minosoft.util.logging.LogMessageType
data class Version( data class Version(
@ -85,7 +86,7 @@ data class Version(
} }
latch.countUp() latch.countUp()
isGettingLoaded = true 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) initializeAssetManger(latch)
val startTime = System.currentTimeMillis() val startTime = System.currentTimeMillis()
@ -99,7 +100,7 @@ data class Version(
Util.readJsonFromStream(assetsManager.readAssetAsStream(Resources.getPixLyzerDataHashByVersion(this))) Util.readJsonFromStream(assetsManager.readAssetAsStream(Resources.getPixLyzerDataHashByVersion(this)))
} catch (exception: Throwable) { } 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... // 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()) { if (isFlattened()) {
throw exception throw exception
} }
@ -112,9 +113,9 @@ data class Version(
mapping.load(this, pixlyzerData) mapping.load(this, pixlyzerData)
latch.countDown() latch.countDown()
if (pixlyzerData.size() > 0) { 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 { } 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 isLoaded = true
isGettingLoaded = false isGettingLoaded = false

View File

@ -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.packets.s2c.play.PositionAndRotationS2CP
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.CountUpAndDownLatch 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 de.bixilon.minosoft.util.logging.LogMessageType
import glm_.vec2.Vec2 import glm_.vec2.Vec2
import glm_.vec2.Vec2i import glm_.vec2.Vec2i
@ -113,6 +113,7 @@ class RenderWindow(
} }
fun init(latch: CountUpAndDownLatch) { fun init(latch: CountUpAndDownLatch) {
Log.log(LogMessageType.RENDERING_LOADING) { "Creating window..." }
// Setup an error callback. The default implementation // Setup an error callback. The default implementation
// will print the error message in System.err. // will print the error message in System.err.
GLFWErrorCallback.createPrint(System.err).set() GLFWErrorCallback.createPrint(System.err).set()
@ -164,6 +165,7 @@ class RenderWindow(
glfwSetWindowPos(windowId, (videoMode.width() - pWidth[0]) / 2, (videoMode.height() - pHeight[0]) / 2) glfwSetWindowPos(windowId, (videoMode.width() - pWidth[0]) / 2, (videoMode.height() - pHeight[0]) / 2)
} }
Log.log(LogMessageType.RENDERING_LOADING) { "Creating context..." }
// Make the OpenGL context current // Make the OpenGL context current
glfwMakeContextCurrent(windowId) glfwMakeContextCurrent(windowId)
// Enable v-sync // Enable v-sync
@ -175,6 +177,7 @@ class RenderWindow(
setSkyColor(RGBColor("#fffe7a")) setSkyColor(RGBColor("#fffe7a"))
Log.log(LogMessageType.RENDERING_LOADING) { "Enabling all open gl features..." }
glEnable(GL_DEPTH_TEST) glEnable(GL_DEPTH_TEST)
glEnable(GL_BLEND) glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
@ -182,6 +185,7 @@ class RenderWindow(
glEnable(GL_CULL_FACE) glEnable(GL_CULL_FACE)
Log.log(LogMessageType.RENDERING_LOADING) { "Generating font and textures..." }
textures.allTextures.add(Texture(RenderConstants.DEBUG_TEXTURE_RESOURCE_LOCATION)) textures.allTextures.add(Texture(RenderConstants.DEBUG_TEXTURE_RESOURCE_LOCATION))
WHITE_TEXTURE = TextureLikeTexture( WHITE_TEXTURE = TextureLikeTexture(
texture = Texture(ResourceLocation("minosoft:textures/white.png")), texture = Texture(ResourceLocation("minosoft:textures/white.png")),
@ -195,16 +199,20 @@ class RenderWindow(
font.preLoadAtlas(textures) font.preLoadAtlas(textures)
Log.log(LogMessageType.RENDERING_LOADING) { "Initializing renderer..." }
for (renderer in rendererMap.values) { for (renderer in rendererMap.values) {
renderer.init() renderer.init()
} }
Log.log(LogMessageType.RENDERING_LOADING) { "Preloading textures..." }
textures.preLoad(connection.assetsManager) textures.preLoad(connection.assetsManager)
font.loadAtlas() font.loadAtlas()
Log.log(LogMessageType.RENDERING_LOADING) { "Loading textures..." }
textures.load() textures.load()
Log.log(LogMessageType.RENDERING_LOADING) { "Post loading renderer..." }
for (renderer in rendererMap.values) { for (renderer in rendererMap.values) {
renderer.postInit() renderer.postInit()
if (renderer is ShaderHolder) { if (renderer is ShaderHolder) {
@ -213,6 +221,7 @@ class RenderWindow(
} }
Log.log(LogMessageType.RENDERING_LOADING) { "Registering glfw callbacks..." }
glfwSetWindowSizeCallback(windowId, object : GLFWWindowSizeCallback() { glfwSetWindowSizeCallback(windowId, object : GLFWWindowSizeCallback() {
override fun invoke(window: Long, width: Int, height: Int) { override fun invoke(window: Long, width: Int, height: Int) {
glViewport(0, 0, width, height) glViewport(0, 0, width, height)
@ -254,11 +263,12 @@ class RenderWindow(
glEnable(GL_DEPTH_TEST) 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.countDown()
latch.waitUntilZero() latch.waitUntilZero()
this.latch.waitUntilZero() this.latch.waitUntilZero()
glfwShowWindow(windowId) glfwShowWindow(windowId)
Log.log(LogMessageType.RENDERING_GENERAL) { "Showing window" }
} }
private fun registerGlobalKeyCombinations() { private fun registerGlobalKeyCombinations() {
@ -280,6 +290,7 @@ class RenderWindow(
} }
fun startRenderLoop() { fun startRenderLoop() {
Log.log(LogMessageType.RENDERING_LOADING) { "Starting loop" }
while (!glfwWindowShouldClose(windowId)) { while (!glfwWindowShouldClose(windowId)) {
if (renderingState == RenderingStates.PAUSED) { if (renderingState == RenderingStates.PAUSED) {
Thread.sleep(100L) Thread.sleep(100L)
@ -343,6 +354,7 @@ class RenderWindow(
} }
fun exit() { fun exit() {
Log.log(LogMessageType.RENDERING_LOADING) { "Destroying render window..." }
// Free the window callbacks and destroy the window // Free the window callbacks and destroy the window
Callbacks.glfwFreeCallbacks(windowId) Callbacks.glfwFreeCallbacks(windowId)
glfwDestroyWindow(windowId) glfwDestroyWindow(windowId)
@ -351,6 +363,7 @@ class RenderWindow(
glfwTerminate() glfwTerminate()
glfwSetErrorCallback(null)!!.free() glfwSetErrorCallback(null)!!.free()
Log.log(LogMessageType.RENDERING_LOADING) { "Render window destroyed!" }
// disconnect // disconnect
connection.disconnect() connection.disconnect()
} }

View File

@ -41,7 +41,7 @@ import de.bixilon.minosoft.terminal.commands.commands.Command
import de.bixilon.minosoft.util.CountUpAndDownLatch import de.bixilon.minosoft.util.CountUpAndDownLatch
import de.bixilon.minosoft.util.ServerAddress import de.bixilon.minosoft.util.ServerAddress
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import de.bixilon.minosoft.util.time.TimeWorker import de.bixilon.minosoft.util.time.TimeWorker
import de.bixilon.minosoft.util.time.TimeWorkerTask import de.bixilon.minosoft.util.time.TimeWorkerTask
@ -158,11 +158,11 @@ class PlayConnection(
} }
latch.waitForChange() 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) network.connect(address)
} catch (exception: Throwable) { } catch (exception: Throwable) {
Log.log(LogMessageType.VERSION_LOADING) { exception } Log.log(LogMessageType.VERSION_LOADING, level = LogLevels.FATAL) { 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) { "Could not load version $version. This version seems to be unsupported" }
version.unload() version.unload()
lastException = MappingsLoadingException("Mappings could not be loaded", exception) lastException = MappingsLoadingException("Mappings could not be loaded", exception)
connectionState = ConnectionStates.FAILED_NO_RETRY connectionState = ConnectionStates.FAILED_NO_RETRY
@ -200,7 +200,7 @@ class PlayConnection(
packet.handle(this) packet.handle(this)
} }
} catch (exception: Throwable) { } catch (exception: Throwable) {
Log.log(LogMessageType.NETWORK_PACKETS_IN_ERROR) { exception } Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.WARN) { exception }
} }
} }

View File

@ -33,6 +33,7 @@ import de.bixilon.minosoft.protocol.protocol.Protocol
import de.bixilon.minosoft.util.DNSUtil import de.bixilon.minosoft.util.DNSUtil
import de.bixilon.minosoft.util.ServerAddress import de.bixilon.minosoft.util.ServerAddress
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import java.util.* import java.util.*
@ -142,7 +143,7 @@ class StatusConnection(
packet.handle(this) packet.handle(this)
} }
} catch (exception: Throwable) { } catch (exception: Throwable) {
Log.log(LogMessageType.NETWORK_PACKETS_IN_ERROR) { exception } Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.WARN) { exception }
} }
} }

View File

@ -28,6 +28,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
import de.bixilon.minosoft.util.Pair; import de.bixilon.minosoft.util.Pair;
import de.bixilon.minosoft.util.ServerAddress; import de.bixilon.minosoft.util.ServerAddress;
import de.bixilon.minosoft.util.logging.Log; 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.logging.LogMessageType;
import javax.crypto.Cipher; import javax.crypto.Cipher;
@ -107,7 +108,7 @@ public class BlockingSocketNetwork extends Network {
var typeAndPacket = prepareS2CPacket(this.inputStream); var typeAndPacket = prepareS2CPacket(this.inputStream);
handlePacket(typeAndPacket.getKey(), typeAndPacket.getValue()); handlePacket(typeAndPacket.getKey(), typeAndPacket.getValue());
} catch (PacketParseException e) { } catch (PacketParseException e) {
Log.printException(e, LogMessageType.NETWORK_PACKETS_IN_ERROR); Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.WARN, e);
} }
} }
this.connection.disconnect(); this.connection.disconnect();
@ -121,7 +122,7 @@ public class BlockingSocketNetwork extends Network {
this.connection.setConnectionState(ConnectionStates.DISCONNECTED); this.connection.setConnectionState(ConnectionStates.DISCONNECTED);
return; return;
} }
Log.printException(exception, LogMessageType.NETWORK_PACKETS_IN_ERROR); Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.WARN, exception);
this.connection.setLastException(exception); this.connection.setLastException(exception);
this.connection.setConnectionState(ConnectionStates.FAILED); this.connection.setConnectionState(ConnectionStates.FAILED);
} }

View File

@ -24,6 +24,7 @@ import de.bixilon.minosoft.protocol.protocol.CryptManager;
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition; import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
import de.bixilon.minosoft.util.ServerAddress; import de.bixilon.minosoft.util.ServerAddress;
import de.bixilon.minosoft.util.logging.Log; 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.logging.LogMessageType;
import javax.crypto.Cipher; import javax.crypto.Cipher;
@ -140,7 +141,7 @@ public class NonBlockingSocketNetwork extends Network {
var typeAndPacket = receiveS2CPacket(decryptData(currentPacketBuffer.array())); var typeAndPacket = receiveS2CPacket(decryptData(currentPacketBuffer.array()));
handlePacket(typeAndPacket.getKey(), typeAndPacket.getValue()); handlePacket(typeAndPacket.getKey(), typeAndPacket.getValue());
} catch (PacketParseException e) { } catch (PacketParseException e) {
Log.printException(e, LogMessageType.NETWORK_PACKETS_IN_ERROR); Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.WARN, e);
} }
currentPacketBuffer.clear(); currentPacketBuffer.clear();
currentPacketBuffer = null; currentPacketBuffer = null;
@ -159,7 +160,7 @@ public class NonBlockingSocketNetwork extends Network {
if (exception instanceof SocketException && exception.getMessage().equals("Socket closed")) { if (exception instanceof SocketException && exception.getMessage().equals("Socket closed")) {
return; return;
} }
Log.printException(exception, LogMessageType.NETWORK_PACKETS_IN_ERROR); Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.WARN, exception);
this.connection.setLastException(exception); this.connection.setLastException(exception);
this.connection.setConnectionState(ConnectionStates.FAILED); this.connection.setConnectionState(ConnectionStates.FAILED);
} }

View File

@ -34,6 +34,6 @@ class HandshakeC2SPacket(
} }
override fun log() { override fun log() {
Log.log(LogMessageType.NETWORK_PACKETS_OUT) { "Handshake packet" } Log.log(LogMessageType.NETWORK_PACKETS_OUT) { "Handshake" }
} }
} }

View File

@ -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.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast
import glm_.vec3.Vec3i import glm_.vec3.Vec3i
@ -42,6 +43,6 @@ class BlockEntityMetaDataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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)" }
} }
} }

View File

@ -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.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import glm_.vec3.Vec3i import glm_.vec3.Vec3i
@ -61,6 +62,6 @@ class BlockSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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)" }
} }
} }

View File

@ -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.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import java.util.* import java.util.*
@ -51,10 +52,10 @@ class ChatMessageS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
ChatTextPositions.ABOVE_HOTBAR -> "[HOTBAR] " ChatTextPositions.ABOVE_HOTBAR -> "[HOTBAR] "
else -> "" 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() { 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\")" }
} }
} }

View File

@ -27,7 +27,7 @@ import de.bixilon.minosoft.util.KUtil.nullCast
import de.bixilon.minosoft.util.Util import de.bixilon.minosoft.util.Util
import de.bixilon.minosoft.util.chunk.ChunkUtil import de.bixilon.minosoft.util.chunk.ChunkUtil
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast
import glm_.vec2.Vec2i import glm_.vec2.Vec2i
@ -108,7 +108,7 @@ class ChunkDataS2CP() : PlayS2CPacket() {
val position = Vec3i(nbt["x"]?.nullCast<Int>()!!, nbt["y"]?.nullCast<Int>()!!, nbt["z"]?.nullCast<Int>()!!) val position = Vec3i(nbt["x"]?.nullCast<Int>()!!, nbt["y"]?.nullCast<Int>()!!, nbt["z"]?.nullCast<Int>()!!)
val resourceLocation = ResourceLocation(nbt["id"]?.nullCast<String>()!!) val resourceLocation = ResourceLocation(nbt["id"]?.nullCast<String>()!!)
val type = buffer.connection.mapping.blockEntityRegistry.get(resourceLocation) ?: let { 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 null
} ?: continue } ?: continue
val entity = type.build(buffer.connection) ?: continue val entity = type.build(buffer.connection) ?: continue
@ -140,6 +140,6 @@ class ChunkDataS2CP() : PlayS2CPacket() {
} }
override fun log() { 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)" }
} }
} }

View File

@ -23,6 +23,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.KUtil import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.chunk.LightUtil.readLightPacket import de.bixilon.minosoft.util.chunk.LightUtil.readLightPacket
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import glm_.vec2.Vec2i import glm_.vec2.Vec2i
import java.util.* import java.util.*
@ -57,7 +58,7 @@ class ChunkLightDataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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) { override fun handle(connection: PlayConnection) {

View File

@ -17,6 +17,7 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.util.KUtil import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.enum.ValuesEnum import de.bixilon.minosoft.util.enum.ValuesEnum
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
class EntityAnimationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { class EntityAnimationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
@ -25,7 +26,7 @@ class EntityAnimationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
override fun log() { 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 { enum class EntityAnimations {

View File

@ -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.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
class EntityMetadataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { class EntityMetadataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
@ -37,6 +38,6 @@ class EntityMetadataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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)" }
} }
} }

View File

@ -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.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import glm_.vec3.Vec3 import glm_.vec3.Vec3
@ -30,6 +31,6 @@ class EntityVelocityS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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)" }
} }
} }

View File

@ -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.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
class HotbarSlotSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { class HotbarSlotSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
@ -29,6 +30,6 @@ class HotbarSlotSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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)" }
} }
} }

View File

@ -31,6 +31,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_20W27A
import de.bixilon.minosoft.util.BitByte import de.bixilon.minosoft.util.BitByte
import de.bixilon.minosoft.util.KUtil.nullCast import de.bixilon.minosoft.util.KUtil.nullCast
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast
@ -178,7 +179,7 @@ class JoinGameS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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 { companion object : ErrorHandler {

View File

@ -24,6 +24,7 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import glm_.vec2.Vec2i import glm_.vec2.Vec2i
import glm_.vec3.Vec3i import glm_.vec3.Vec3i
@ -99,6 +100,6 @@ class MassBlockSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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})" }
} }
} }

View File

@ -24,6 +24,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.Util import de.bixilon.minosoft.util.Util
import de.bixilon.minosoft.util.chunk.ChunkUtil import de.bixilon.minosoft.util.chunk.ChunkUtil
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import glm_.vec2.Vec2i import glm_.vec2.Vec2i
import java.util.* import java.util.*
@ -87,6 +88,6 @@ class MassChunkDataS2CP() : PlayS2CPacket() {
} }
override fun log() { 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})" }
} }
} }

View File

@ -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.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast
@ -23,6 +24,6 @@ class NBTQueryResponseS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
val nbt: Map<String, Any> = buffer.readNBT()?.compoundCast()!! val nbt: Map<String, Any> = buffer.readNBT()?.compoundCast()!!
override fun log() { 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)" }
} }
} }

View File

@ -18,6 +18,7 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.BitByte.isBit import de.bixilon.minosoft.util.BitByte.isBit
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
class PlayerAbilitiesS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { class PlayerAbilitiesS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
@ -45,7 +46,7 @@ class PlayerAbilitiesS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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) { override fun handle(connection: PlayConnection) {

View File

@ -21,6 +21,7 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.BitByte import de.bixilon.minosoft.util.BitByte
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import glm_.vec3.Vec3 import glm_.vec3.Vec3
@ -81,6 +82,6 @@ class PositionAndRotationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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)" }
} }
} }

View File

@ -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.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast
@ -94,6 +95,6 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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)" }
} }
} }

View File

@ -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.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
class ServerDifficultyS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { class ServerDifficultyS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
@ -37,6 +38,6 @@ class ServerDifficultyS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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})" }
} }
} }

View File

@ -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.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
class SetExperienceS2CP() : PlayS2CPacket() { class SetExperienceS2CP() : PlayS2CPacket() {
@ -55,6 +56,6 @@ class SetExperienceS2CP() : PlayS2CPacket() {
} }
override fun log() { 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)" }
} }
} }

View File

@ -21,6 +21,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.KUtil.unsafeCast import de.bixilon.minosoft.util.KUtil.unsafeCast
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import glm_.vec3.Vec3i import glm_.vec3.Vec3i
@ -52,6 +53,6 @@ class SetSignTextS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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" }
} }
} }

View File

@ -24,7 +24,7 @@ import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.Util import de.bixilon.minosoft.util.Util
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import glm_.vec3.Vec3 import glm_.vec3.Vec3
import java.util.* import java.util.*
@ -78,7 +78,7 @@ class SpawnPlayerS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
if (metaData != null) { if (metaData != null) {
entity.entityMetaData = metaData entity.entityMetaData = metaData
if (StaticConfiguration.VERBOSE_ENTITY_META_DATA_LOGGING) { 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() { 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)" }
} }
} }

View File

@ -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.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
import java.util.* import java.util.*
@ -174,7 +175,7 @@ class TabListItemS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
} }
override fun log() { 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" }
} }

View File

@ -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.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log 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.logging.LogMessageType
import glm_.vec3.Vec3i import glm_.vec3.Vec3i
@ -30,6 +31,6 @@ class WorldEventS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
val isGlobal: Boolean = buffer.readBoolean() val isGlobal: Boolean = buffer.readBoolean()
override fun log() { 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)" }
} }
} }

View File

@ -16,7 +16,8 @@ package de.bixilon.minosoft.util
import de.bixilon.minosoft.Minosoft import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.data.mappings.ResourceLocation import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition 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 de.bixilon.minosoft.util.logging.LogMessageType
import java.text.DateFormat import java.text.DateFormat
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
@ -103,8 +104,8 @@ object GitInfo {
IS_INITIALIZED = true IS_INITIALIZED = true
} catch (exception: Throwable) { } catch (exception: Throwable) {
log(LogMessageType.OTHER_DEBUG, message = exception) Log.log(LogMessageType.OTHER, level = LogLevels.WARN) { exception }
log(LogMessageType.OTHER_ERROR, message = "Can not load git information.", formatting = arrayOf()) Log.log(LogMessageType.OTHER, level = LogLevels.WARN) { "Could not load git information." }
} }
} }
} }

View File

@ -31,8 +31,8 @@ object Log {
private val LOG_QUEUE = LinkedBlockingQueue<MessageToSend>() private val LOG_QUEUE = LinkedBlockingQueue<MessageToSend>()
private val SYSTEM_ERR_STREAM = System.err private val SYSTEM_ERR_STREAM = System.err
private val SYSTEM_OUT_STREAM = System.out private val SYSTEM_OUT_STREAM = System.out
private val ERROR_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER_ERROR) private val ERROR_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER, LogLevels.WARN)
private val OUT_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER_INFO) private val OUT_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER, LogLevels.INFO)
init { init {
@ -48,11 +48,12 @@ object Log {
message.parts.add(TextComponent("[${TIME_FORMAT.format(messageToSend.time)}] ")) message.parts.add(TextComponent("[${TIME_FORMAT.format(messageToSend.time)}] "))
message.parts.add(TextComponent("[${messageToSend.thread.name}] ")) message.parts.add(TextComponent("[${messageToSend.thread.name}] "))
message.parts.add(TextComponent("[${messageToSend.logMessageType}] ")) message.parts.add(TextComponent("[${messageToSend.logMessageType}] "))
message.parts.add(TextComponent("[${messageToSend.level}] "))
messageToSend.additionalPrefix?.let { messageToSend.additionalPrefix?.let {
message.parts.add(it) message.parts.add(it)
} }
message.parts.add(messageToSend.message) 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) { val stream = if (messageToSend.logMessageType.error) {
SYSTEM_ERR_STREAM SYSTEM_ERR_STREAM
@ -71,9 +72,13 @@ object Log {
@DoNotCall @DoNotCall
@JvmOverloads @JvmOverloads
@JvmStatic @JvmStatic
fun log(logMessageType: LogMessageType, additionalPrefix: ChatComponent? = null, message: Any, vararg formatting: Any) { fun log(logMessageType: LogMessageType, level: LogLevels = LogLevels.INFO, additionalPrefix: ChatComponent? = null, message: Any, vararg formatting: Any) {
if (Minosoft.config != null && !Minosoft.config.config.general.enabledLogTypes.contains(logMessageType)) { if (Minosoft.config != null) {
return Minosoft.config.config.general.log[logMessageType]?.let {
if (it.ordinal < level.ordinal) {
return
}
}
} }
val formattedMessage = when (message) { val formattedMessage = when (message) {
is ChatComponent -> message is ChatComponent -> message
@ -91,6 +96,7 @@ object Log {
message = formattedMessage, message = formattedMessage,
time = System.currentTimeMillis(), time = System.currentTimeMillis(),
logMessageType = logMessageType, logMessageType = logMessageType,
level = level,
thread = Thread.currentThread(), thread = Thread.currentThread(),
additionalPrefix = additionalPrefix, additionalPrefix = additionalPrefix,
) )
@ -98,11 +104,20 @@ object Log {
} }
@JvmStatic @JvmStatic
fun log(logMessageType: LogMessageType, additionalPrefix: ChatComponent? = null, messageBuilder: () -> Any) { fun log(logMessageType: LogMessageType, level: LogLevels = LogLevels.INFO, additionalPrefix: ChatComponent? = null, messageBuilder: () -> Any) {
if (!Minosoft.config.config.general.enabledLogTypes.contains(logMessageType)) { if (Minosoft.config != null) {
return 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 @JvmStatic
@ -110,63 +125,69 @@ object Log {
log(logMessageType, additionalPrefix = null, messageBuilder = messageBuilder) 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 @JvmStatic
fun printException(exception: Throwable, logMessageType: LogMessageType) { fun printException(exception: Throwable, logMessageType: LogMessageType) {
log(logMessageType, message = exception) 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 @JvmStatic
fun fatal(message: Any, vararg formatting: Any) { 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 @JvmStatic
fun error(message: Any, vararg formatting: Any) { 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 @JvmStatic
fun info(message: Any, vararg formatting: Any) { 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 @JvmStatic
fun debug(message: Any, vararg formatting: Any) { 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 @JvmStatic
fun verbose(message: Any, vararg formatting: Any) { 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 @JvmStatic
fun protocol(message: Any, vararg formatting: Any) { 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 @JvmStatic
fun warn(message: Any, vararg formatting: Any) { 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 @JvmStatic
fun game(message: Any, vararg formatting: Any) { 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 @JvmStatic
fun mojang(message: Any, vararg formatting: Any) { 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)
} }
} }

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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,
;
}

View File

@ -18,8 +18,9 @@ import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.enum.ValuesEnum import de.bixilon.minosoft.util.enum.ValuesEnum
enum class LogMessageType( enum class LogMessageType(
val color: RGBColor, val defaultColor: RGBColor,
val enabledDefault: Boolean = true, val colorMap: Map<LogLevels, RGBColor> = mapOf(),
val defaultLevel: LogLevels = LogLevels.INFO,
val error: Boolean = false, val error: Boolean = false,
) { ) {
GENERAL(ChatColors.WHITE), GENERAL(ChatColors.WHITE),
@ -27,12 +28,18 @@ enum class LogMessageType(
JAVAFX(ChatColors.DARK_GRAY), JAVAFX(ChatColors.DARK_GRAY),
VERSION_LOADING(ChatColors.YELLOW), VERSION_LOADING(ChatColors.YELLOW),
ASSETS(ChatColors.BLACK),
NETWORK_RESOLVING(ChatColors.DARK_GREEN), NETWORK_RESOLVING(ChatColors.DARK_GREEN),
NETWORK_STATUS(ChatColors.DARK_GREEN, enabledDefault = false), NETWORK_STATUS(ChatColors.DARK_GREEN),
NETWORK_PACKETS_IN(ChatColors.BLUE, enabledDefault = false), NETWORK_PACKETS_IN(ChatColors.BLUE, mapOf(
NETWORK_PACKETS_IN_ERROR(ChatColors.RED, error = true), LogLevels.FATAL to ChatColors.DARK_RED,
NETWORK_PACKETS_OUT(ChatColors.DARK_AQUA, enabledDefault = false), 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_GENERAL(ChatColors.GREEN),
RENDERING_LOADING(ChatColors.GREEN), RENDERING_LOADING(ChatColors.GREEN),
@ -40,25 +47,25 @@ enum class LogMessageType(
CHAT_IN(ChatColors.LIGHT_PURPLE), CHAT_IN(ChatColors.LIGHT_PURPLE),
CHAT_OUT(ChatColors.LIGHT_PURPLE), CHAT_OUT(ChatColors.LIGHT_PURPLE),
OTHER_INFO(ChatColors.WHITE), OTHER(ChatColors.WHITE, mapOf(
OTHER_DEBUG(ChatColors.YELLOW), LogLevels.FATAL to ChatColors.DARK_RED,
OTHER_ERROR(ChatColors.RED, error = true), LogLevels.WARN to ChatColors.RED,
OTHER_FATAL(ChatColors.DARK_RED, error = true), LogLevels.VERBOSE to ChatColors.YELLOW,
)),
; ;
companion object : ValuesEnum<LogMessageType> { companion object : ValuesEnum<LogMessageType> {
override val VALUES: Array<LogMessageType> = values() override val VALUES: Array<LogMessageType> = values()
override val NAME_MAP: Map<String, LogMessageType> = KUtil.getEnumValues(VALUES) override val NAME_MAP: Map<String, LogMessageType> = KUtil.getEnumValues(VALUES)
val DEFAULT_LOG_MESSAGE_TYPES = let { val DEFAULT_LOG_MAP: Map<LogMessageType, LogLevels> = let {
val ret: MutableSet<LogMessageType> = mutableSetOf() val ret: MutableMap<LogMessageType, LogLevels> = mutableMapOf()
for (value in VALUES) { for (value in VALUES) {
if (value.enabledDefault) { ret[value] = value.defaultLevel
ret += value
}
} }
ret.toSet()
ret.toMap()
} }
} }
} }

View File

@ -14,9 +14,12 @@ package de.bixilon.minosoft.util.logging
import java.io.PrintStream 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) { override fun print(string: String) {
Log.log(message = string, logMessageType = level) Log.log(message = string, logMessageType = type, level = level)
} }
} }

View File

@ -19,6 +19,7 @@ data class MessageToSend(
val message: ChatComponent, val message: ChatComponent,
val time: Long, val time: Long,
val logMessageType: LogMessageType, val logMessageType: LogMessageType,
val level: LogLevels,
val thread: Thread, val thread: Thread,
val additionalPrefix: ChatComponent? = null, val additionalPrefix: ChatComponent? = null,
) )

View File

@ -51,7 +51,7 @@ public final class MojangAuthentication {
try { try {
response = HTTP.postJson(ProtocolDefinition.MOJANG_URL_LOGIN, payload); response = HTTP.postJson(ProtocolDefinition.MOJANG_URL_LOGIN, payload);
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
Log.printException(e, LogMessageType.OTHER_INFO); Log.printException(e, LogMessageType.OTHER);
throw new NoNetworkConnectionException(e); throw new NoNetworkConnectionException(e);
} }
if (response == null) { if (response == null) {