From 615de9ef358977ae835946b2449994821cdbb3c6 Mon Sep 17 00:00:00 2001 From: liujiahua123123 Date: Sun, 29 Sep 2019 21:18:07 +0800 Subject: [PATCH] miraiAPI --- .../src/main/java/net/mamoe/mirai/MiraiAPI.java | 5 +++++ .../main/java/net/mamoe/mirai/MiraiConsole.java | 3 +++ .../src/main/java/net/mamoe/mirai/MiraiMain.java | 2 ++ .../main/java/net/mamoe/mirai/utils/MiraiLogger.kt | 14 +++++++++++--- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/mirai-api/src/main/java/net/mamoe/mirai/MiraiAPI.java b/mirai-api/src/main/java/net/mamoe/mirai/MiraiAPI.java index add6345c5..b074181b7 100644 --- a/mirai-api/src/main/java/net/mamoe/mirai/MiraiAPI.java +++ b/mirai-api/src/main/java/net/mamoe/mirai/MiraiAPI.java @@ -1,5 +1,6 @@ package net.mamoe.mirai; +import java.io.PrintStream; import java.util.ArrayList; import java.util.List; @@ -32,6 +33,10 @@ public class MiraiAPI { MiraiMain.main(args); } + public static void setLogger(PrintStream stream){ + MiraiServer.getInstance().getLogger().setOutPutStream(stream); + } + public static String getMiraiVersion(){ return MiraiServer.MIRAI_VERSION; } diff --git a/mirai-console/src/main/java/net/mamoe/mirai/MiraiConsole.java b/mirai-console/src/main/java/net/mamoe/mirai/MiraiConsole.java index 4146bd06b..955c5c176 100644 --- a/mirai-console/src/main/java/net/mamoe/mirai/MiraiConsole.java +++ b/mirai-console/src/main/java/net/mamoe/mirai/MiraiConsole.java @@ -15,4 +15,7 @@ public class MiraiConsole { } + public void log(Object o){ + System.out.println(o); + } } diff --git a/mirai-core/src/main/java/net/mamoe/mirai/MiraiMain.java b/mirai-core/src/main/java/net/mamoe/mirai/MiraiMain.java index 17a003ab8..052fc1864 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/MiraiMain.java +++ b/mirai-core/src/main/java/net/mamoe/mirai/MiraiMain.java @@ -3,6 +3,8 @@ package net.mamoe.mirai; import lombok.Getter; +import java.io.PrintStream; + /** * @author NaturalHG */ diff --git a/mirai-core/src/main/java/net/mamoe/mirai/utils/MiraiLogger.kt b/mirai-core/src/main/java/net/mamoe/mirai/utils/MiraiLogger.kt index 04b245e70..424d58034 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/utils/MiraiLogger.kt +++ b/mirai-core/src/main/java/net/mamoe/mirai/utils/MiraiLogger.kt @@ -3,6 +3,7 @@ package net.mamoe.mirai.utils import net.mamoe.mirai.Bot import net.mamoe.mirai.network.packet.ServerPacket import net.mamoe.mirai.network.packet.goto +import java.io.PrintStream import java.text.SimpleDateFormat import java.util.* @@ -13,6 +14,12 @@ import java.util.* * @author NaturalHG */ object MiraiLogger { + var stream:PrintStream = System.out + + fun setOutPutStream(stream: PrintStream) { + this.stream = stream + } + fun log(o: Any?) = info(o) fun println(o: Any?) = info(o) fun info(o: Any?) = this.print(o.toString(), LoggerTextFormat.RESET) @@ -28,16 +35,17 @@ object MiraiLogger { fun catching(e: Throwable) { e.printStackTrace() - /* + /** this.print(e.message) this.print(e.localizedMessage) - this.print(e.cause.toString())*/ + this.print(e.cause.toString()) + */ } @Synchronized private fun print(value: String?, color: LoggerTextFormat = LoggerTextFormat.WHITE) { val s = SimpleDateFormat("MM-dd HH:mm:ss").format(Date()) - kotlin.io.println("$color[Mirai] $s : $value") + stream.println("$color[Mirai] $s : $value") } }