From fb4d94f718a0800d67d6dd28d6852ce841eeddab Mon Sep 17 00:00:00 2001 From: NikkyAI Date: Sat, 10 Feb 2018 19:05:10 +0100 Subject: [PATCH] replace logger with System.out until we find a way to log version agnostic --- 1.11.2/build.gradle | 2 +- .../src/main/kotlin/matterlink/MatterLink.kt | 3 +++ 1.12.2/build.gradle | 2 +- .../src/main/kotlin/matterlink/MatterLink.kt | 3 +++ build.gradle | 15 +++++++-------- core/build.gradle | 2 +- core/src/main/kotlin/matterlink/IMatterLink.kt | 14 +++++++------- .../matterlink/bridge/HttpStreamConnection.kt | 12 ++++++------ .../kotlin/matterlink/bridge/MessageHandler.kt | 18 +++++++++--------- .../matterlink/bridge/ServerChatHandler.kt | 14 +++++++------- .../bridge/command/BridgeCommandRegistry.kt | 4 ++-- .../kotlin/matterlink/handlers/ChatHandler.kt | 4 ++-- 12 files changed, 49 insertions(+), 44 deletions(-) diff --git a/1.11.2/build.gradle b/1.11.2/build.gradle index aa3f425..1808215 100644 --- a/1.11.2/build.gradle +++ b/1.11.2/build.gradle @@ -45,7 +45,7 @@ shadowJar { minecraft { version = mc_version + "-" + forge_version - runDir = "../run" + runDir = "run" mappings = mcp_mappings diff --git a/1.11.2/src/main/kotlin/matterlink/MatterLink.kt b/1.11.2/src/main/kotlin/matterlink/MatterLink.kt index fe431de..b2e7566 100644 --- a/1.11.2/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.11.2/src/main/kotlin/matterlink/MatterLink.kt @@ -9,11 +9,14 @@ import net.minecraft.util.text.TextComponentString import net.minecraftforge.fml.common.FMLCommonHandler import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.* +import org.apache.logging.log4j.Logger const val MODID = "matterlink" const val NAME = "MatterLink" const val VERSION = "@VERSION@" +lateinit var logger: Logger + @Mod( modid = MODID, name = NAME, version = VERSION, diff --git a/1.12.2/build.gradle b/1.12.2/build.gradle index 8dd9869..c071fa1 100644 --- a/1.12.2/build.gradle +++ b/1.12.2/build.gradle @@ -45,7 +45,7 @@ shadowJar { minecraft { version = mc_version + "-" + forge_version - runDir = "../run" + runDir = "run" mappings = mcp_mappings diff --git a/1.12.2/src/main/kotlin/matterlink/MatterLink.kt b/1.12.2/src/main/kotlin/matterlink/MatterLink.kt index fe431de..b2e7566 100644 --- a/1.12.2/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.12.2/src/main/kotlin/matterlink/MatterLink.kt @@ -9,11 +9,14 @@ import net.minecraft.util.text.TextComponentString import net.minecraftforge.fml.common.FMLCommonHandler import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.* +import org.apache.logging.log4j.Logger const val MODID = "matterlink" const val NAME = "MatterLink" const val VERSION = "@VERSION@" +lateinit var logger: Logger + @Mod( modid = MODID, name = NAME, version = VERSION, diff --git a/build.gradle b/build.gradle index ab78b89..68253b2 100644 --- a/build.gradle +++ b/build.gradle @@ -3,18 +3,17 @@ plugins { id 'idea' } + subprojects { apply plugin: "kotlin" - apply plugin: 'idea' - - idea { - module { - excludeDirs += [file("run")] - } - } + apply plugin: "idea" if(name != "core") { - + idea { + module { + excludeDirs += [file("run")] + } + } repositories { jcenter() diff --git a/core/build.gradle b/core/build.gradle index b7d33de..51f784e 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -20,7 +20,7 @@ repositories { dependencies { compile 'org.apache.httpcomponents:httpclient:4.3.3' compile 'commons-logging:commons-logging:1.1.3' - compile group: "org.apache.logging.log4j", name: "log4j-api", version: '2.8.1' +// compile group: "org.apache.logging.log4j", name: "log4j-api", version: '2.8.1' compile 'com.google.code.gson:gson:2.8.0' compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" } diff --git a/core/src/main/kotlin/matterlink/IMatterLink.kt b/core/src/main/kotlin/matterlink/IMatterLink.kt index 36e107f..e5865aa 100644 --- a/core/src/main/kotlin/matterlink/IMatterLink.kt +++ b/core/src/main/kotlin/matterlink/IMatterLink.kt @@ -1,10 +1,10 @@ package matterlink import matterlink.bridge.MessageHandler -import org.apache.logging.log4j.Logger +//import org.apache.logging.log4j.Logger lateinit var instance: IMatterLink -lateinit var logger: Logger +//lateinit var logger: Logger abstract class IMatterLink { var interrupted: Boolean = false @@ -15,9 +15,9 @@ abstract class IMatterLink { fun connect() { if (MessageHandler.start(clear = true)) { - logger.info("Connected to matterbridge relay") + println("Connected to matterbridge relay") } else { - logger.error("Connection to matterbridge relay failed.") + System.err.println("Connection to matterbridge relay failed.") } } @@ -28,11 +28,11 @@ abstract class IMatterLink { fun reconnect(tick: Int) { if(tick % 20 == 0 && interrupted) { - logger.info("Trying to reconnect") + println("Trying to reconnect") if (MessageHandler.start(clear = false)) { - logger.info("Reconnected to matterbridge relay") + println("Reconnected to matterbridge relay") } else { - logger.error("Reconnection to matterbridge relay failed.") + System.err.println("Reconnection to matterbridge relay failed.") } } } diff --git a/core/src/main/kotlin/matterlink/bridge/HttpStreamConnection.kt b/core/src/main/kotlin/matterlink/bridge/HttpStreamConnection.kt index 5f73f09..81682aa 100644 --- a/core/src/main/kotlin/matterlink/bridge/HttpStreamConnection.kt +++ b/core/src/main/kotlin/matterlink/bridge/HttpStreamConnection.kt @@ -1,7 +1,7 @@ package matterlink.bridge; import matterlink.instance -import matterlink.logger +//import matterlink.logger import org.apache.http.client.methods.HttpGet import org.apache.http.impl.client.HttpClients import java.io.InputStream @@ -24,7 +24,7 @@ class HttpStreamConnection(getClosure: () -> HttpGet, clearClosure: () -> HttpGe if (clear) { val r = client.execute(clearGet) r.entity.content.bufferedReader().forEachLine { - logger.debug("skipping $it") + println("DEBUG: skipping $it") } } val response = client.execute(get) @@ -39,7 +39,7 @@ class HttpStreamConnection(getClosure: () -> HttpGet, clearClosure: () -> HttpGe if (chars > 0) { buffer += String(buf.dropLast(buf.count() - chars).toByteArray()) - logger.debug(buffer) + println("DEBUG: " + buffer) while (buffer.contains("\n")) { val line = buffer.substringBefore("\n") @@ -52,14 +52,14 @@ class HttpStreamConnection(getClosure: () -> HttpGet, clearClosure: () -> HttpGe } } catch (e: SocketException) { if (!cancelled) { - logger.error("Bridge Connection interrupted...") + System.err.println("Bridge Connection interrupted...") instance.interrupted = true //TODO: mark connection as interrupted and try to reconnect } } - logger.debug("closing stream") + println("DEBUG: closing stream") content.close() - logger.debug("thread finished") + println("DEBUG: thread finished") onClose() return } diff --git a/core/src/main/kotlin/matterlink/bridge/MessageHandler.kt b/core/src/main/kotlin/matterlink/bridge/MessageHandler.kt index 0a22668..f4d7aba 100644 --- a/core/src/main/kotlin/matterlink/bridge/MessageHandler.kt +++ b/core/src/main/kotlin/matterlink/bridge/MessageHandler.kt @@ -1,7 +1,7 @@ package matterlink.bridge import matterlink.config.cfg -import matterlink.logger +//import matterlink.logger import org.apache.http.client.methods.HttpGet import org.apache.http.client.methods.HttpPost import org.apache.http.client.methods.HttpRequestBase @@ -30,7 +30,7 @@ object MessageHandler { } private fun createThread(clear: Boolean = true): HttpStreamConnection { - logger.info("Attempting to open bridge connection.") + println("Attempting to open bridge connection.") return HttpStreamConnection( { HttpGet(cfg!!.connect.url + "/api/stream").apply { @@ -46,10 +46,10 @@ object MessageHandler { rcvQueue.add( ApiMessage.decode(it) ) - logger.debug("Received: " + it) +// println("Received: " + it) }, { - logger.info("Bridge connection closed!") + println("Bridge connection closed!") connected = false }, clear @@ -58,13 +58,13 @@ object MessageHandler { fun transmit(msg: ApiMessage) { if (connected && streamConnection.isAlive) { - logger.debug("Transmitting: " + msg) + println("Transmitting: " + msg) transmitMessage(msg) } } fun stop() { - logger.info("Closing bridge connection...") + println("Closing bridge connection...") // MessageHandler.transmit(ApiMessage(text="bridge closing", username="Server")) streamConnection.close() } @@ -93,14 +93,14 @@ object MessageHandler { val response = client.execute(post) val code = response.statusLine.statusCode if (code != 200) { - logger.error("Server returned $code for $post") + System.err.println("Server returned $code for $post") } sendErrors = 0 } catch (e: IOException) { - logger.error("sending message caused $e") + System.err.println("sending message caused $e") sendErrors++ if (sendErrors > 5) { - logger.error("caught too many errors, closing bridge") + System.err.println("caught too many errors, closing bridge") stop() } } diff --git a/core/src/main/kotlin/matterlink/bridge/ServerChatHandler.kt b/core/src/main/kotlin/matterlink/bridge/ServerChatHandler.kt index f0187f2..4c07e75 100644 --- a/core/src/main/kotlin/matterlink/bridge/ServerChatHandler.kt +++ b/core/src/main/kotlin/matterlink/bridge/ServerChatHandler.kt @@ -1,6 +1,6 @@ package matterlink.bridge -import matterlink.logger +//import matterlink.logger import matterlink.instance import matterlink.bridge.command.BridgeCommandRegistry import matterlink.config.cfg @@ -13,7 +13,7 @@ object ServerChatHandler { fun writeIncomingToChat(tick: Int) { instance.reconnect(tick) if (MessageHandler.rcvQueue.isNotEmpty()) - logger.debug("incoming: " + MessageHandler.rcvQueue.toString()) + println("incoming: " + MessageHandler.rcvQueue.toString()) val nextMessage = MessageHandler.rcvQueue.poll() if (nextMessage != null && nextMessage.gateway == cfg!!.connect.gateway) { @@ -30,11 +30,11 @@ object ServerChatHandler { val user = nextMessage.username val text = nextMessage.text val json = nextMessage.encode() - logger.debug("Threw out message with unhandled event: ${nextMessage.event}") - logger.debug(" Message contents:") - logger.debug(" User: $user") - logger.debug(" Text: $text") - logger.debug(" JSON: $json") + println("Threw out message with unhandled event: ${nextMessage.event}") + println(" Message contents:") + println(" User: $user") + println(" Text: $text") + println(" JSON: $json") return } } diff --git a/core/src/main/kotlin/matterlink/bridge/command/BridgeCommandRegistry.kt b/core/src/main/kotlin/matterlink/bridge/command/BridgeCommandRegistry.kt index f051fa9..f240354 100644 --- a/core/src/main/kotlin/matterlink/bridge/command/BridgeCommandRegistry.kt +++ b/core/src/main/kotlin/matterlink/bridge/command/BridgeCommandRegistry.kt @@ -1,7 +1,7 @@ package matterlink.bridge.command import matterlink.config.cfg -import matterlink.logger +//import matterlink.logger import java.util.* object BridgeCommandRegistry { @@ -23,7 +23,7 @@ object BridgeCommandRegistry { fun register(cmd: IBridgeCommand): Boolean { if (cmd.name.isBlank() || commandMap.containsKey(cmd.name)) { - logger.error("Failed to register command: '${cmd.name}'") + System.out.println("Failed to register command: '${cmd.name}'") return false } commandMap[cmd.name] = cmd diff --git a/core/src/main/kotlin/matterlink/handlers/ChatHandler.kt b/core/src/main/kotlin/matterlink/handlers/ChatHandler.kt index 90aa90e..48211df 100644 --- a/core/src/main/kotlin/matterlink/handlers/ChatHandler.kt +++ b/core/src/main/kotlin/matterlink/handlers/ChatHandler.kt @@ -2,7 +2,7 @@ package matterlink.handlers import matterlink.bridge.ApiMessage import matterlink.bridge.MessageHandler -import matterlink.logger +//import matterlink.logger object ChatHandler { fun handleChat(user: String, msg: String) { @@ -12,7 +12,7 @@ object ChatHandler { username = user, text = message )) - else -> logger.warn("dropped blank message by '$user'") + else -> println("WARN: dropped blank message by '$user'") } } }