replace logger with System.out until we find a way to log version agnostic

This commit is contained in:
NikkyAI 2018-02-10 19:05:10 +01:00 committed by Unknown
parent 7d02199eb1
commit fb4d94f718
12 changed files with 49 additions and 44 deletions

View File

@ -45,7 +45,7 @@ shadowJar {
minecraft {
version = mc_version + "-" + forge_version
runDir = "../run"
runDir = "run"
mappings = mcp_mappings

View File

@ -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,

View File

@ -45,7 +45,7 @@ shadowJar {
minecraft {
version = mc_version + "-" + forge_version
runDir = "../run"
runDir = "run"
mappings = mcp_mappings

View File

@ -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,

View File

@ -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()

View File

@ -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"
}

View File

@ -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.")
}
}
}

View File

@ -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
}

View File

@ -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()
}
}

View File

@ -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
}
}

View File

@ -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

View File

@ -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'")
}
}
}