From ecef73fad408ed5e285bbadc10750cfbe62b67d7 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Sat, 11 Dec 2021 00:10:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5=20messiva=20=E4=BD=9C?= =?UTF-8?q?=E4=B8=BA=20log=20=E7=B3=BB=E7=BB=9F=EF=BC=8C=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E4=BA=86=20version=20=E5=91=BD=E4=BB=A4=E7=9A=84=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 + gradle.properties | 4 +- .../cono/morny/GradleProjectConfigures.java | 4 +- src/main/java/cc/sukazyo/cono/morny/Log.java | 14 ++++ .../java/cc/sukazyo/cono/morny/Logger.java | 80 ------------------- .../cc/sukazyo/cono/morny/MornyCoeur.java | 2 +- .../cc/sukazyo/cono/morny/ServerMain.java | 2 +- .../morny/bot/api/EventListenerManager.java | 2 +- .../morny/bot/event/OnCommandExecute.java | 10 +-- .../data/tracker/TrackerDataManager.java | 2 +- 10 files changed, 31 insertions(+), 92 deletions(-) create mode 100644 src/main/java/cc/sukazyo/cono/morny/Log.java delete mode 100644 src/main/java/cc/sukazyo/cono/morny/Logger.java diff --git a/build.gradle b/build.gradle index 7c3c566..2b36477 100644 --- a/build.gradle +++ b/build.gradle @@ -14,12 +14,15 @@ mainClassName = 'cc.sukazyo.cono.morny.ServerMain' repositories { mavenCentral() + maven { name '-ws'; url 'https://mvn.sukazyo.cc' } } dependencies { compileOnlyApi "com.github.spotbugs:spotbugs-annotations:${libSpotbugsVersion}" + api "cc.sukazyo:messiva:${libMessivaVersion}" + implementation "com.github.pengrad:java-telegram-bot-api:${libJavaTelegramBotApiVersion}" testImplementation "org.junit.jupiter:junit-jupiter-api:${libJunitVersion}" diff --git a/gradle.properties b/gradle.properties index 7d6499a..40423cd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,13 @@ ## Core -VERSION = 0.4.1.0 +VERSION = 0.4.1.1 # dependencies libSpotbugsVersion = 4.5.0 +libMessivaVersion = 0.1.0.0 + libJavaTelegramBotApiVersion = 5.5.0 libJunitVersion = 5.8.2 diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index 5b74266..07e1123 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -4,6 +4,6 @@ package cc.sukazyo.cono.morny; * the final field that will be updated by gradle automatically. */ public class GradleProjectConfigures { - public static final String VERSION = "0.4.1.0"; - public static final long COMPILE_TIMESTAMP = 1639069681128L; + public static final String VERSION = "0.4.1.1"; + public static final long COMPILE_TIMESTAMP = 1639152431845L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/Log.java b/src/main/java/cc/sukazyo/cono/morny/Log.java new file mode 100644 index 0000000..7109fcb --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/Log.java @@ -0,0 +1,14 @@ +package cc.sukazyo.cono.morny; + +import cc.sukazyo.messiva.Logger; +import cc.sukazyo.messiva.appender.ConsoleAppender; + +/** + * Morny 的简单控制台 log 记录器 + */ +public class Log { + + /** Morny 的 Logger 实例 */ + public static final Logger logger = new Logger(new ConsoleAppender()); + +} diff --git a/src/main/java/cc/sukazyo/cono/morny/Logger.java b/src/main/java/cc/sukazyo/cono/morny/Logger.java deleted file mode 100644 index f48b6d1..0000000 --- a/src/main/java/cc/sukazyo/cono/morny/Logger.java +++ /dev/null @@ -1,80 +0,0 @@ -package cc.sukazyo.cono.morny; - -import cc.sukazyo.cono.morny.util.StringUtils; - -import javax.annotation.Nonnull; - -/** - * Morny 的简单控制台 log 记录器 - */ -public class Logger { - - /** Morny 的控制台 logger 实例 */ - public static final Logger logger = new Logger(); - - /** - * [INFO] 级别的 log 消息 - * @see #formatMessage(String, String) 输出整理规则 - * @param message 消息文本,支持多行 - */ - public void info(@Nonnull String message) { - System.out.println(formatMessage(message, "INFO")); - } - - /** - * [WARN] 级别的 log 消息
- * {@link #warning(String)} 的重写 - * @see #formatMessage(String, String) 输出整理规则 - * @see #warning(String) 源方法 - * @param message 消息文本,支持多行 - */ - public void warn (@Nonnull String message) { - warning(message); - } - - /** - * [WARN] 级别的 log 消息 - * @see #formatMessage(String, String) 输出整理规则 - * @see #warn(String) 别名:warn - * @param message 消息文本,支持多行 - */ - public void warning (@Nonnull String message) { - System.out.println(formatMessage(message, "WARN")); - } - - /** - * [ERRO] 级别的 log 消息 - * @see #formatMessage(String, String) 输出整理规则 - * @param message 消息文本,支持多行 - */ - public void error (@Nonnull String message) { - System.out.println(formatMessage(message, "ERRO")); - } - - /** - * 将传入的消息和消息元数据重新整理为固定格式
- *
- * 这个方法会{@link System#currentTimeMillis() 获取当前时间}和{@link Thread#currentThread() 当前线程}的名称, - * 然后将数据整理为 {@code [][][]} 格式。
- * 如果消息是多行的,则每行的开头都会被加入 {@code [][][]} 这样的前缀, - * 不过,前缀中 {@code [][]} 会被转换为等长的 {@code '} 字串。 - *
- * 最终的 format 格式将会类似于以下的模样:

-[1019284827][EVT388223][INFO]Something message got:
-'''''''''''''''''''''''[INFO] - data source: 19773
-'''''''''''''''''''''''[INFO] - message raw: noh2q0jwd9j-jn-9jq92-ed
-	 * 
- * - * @param message 消息文本,支持多行 - * @param level log级别,考虑到对齐,推荐使用四位窄字元 - * @return 整理后的字符串 - */ - @Nonnull - private String formatMessage (@Nonnull String message, @Nonnull String level) { - final String prompt = String.format("[%s][%s]", System.currentTimeMillis(), Thread.currentThread().getName()); - final String levelStr = String.format("[%s]", level); - final String newline = "\n" + StringUtils.repeatChar('\'', prompt.length()) + levelStr; - return prompt + levelStr + message.replaceAll("\\n", newline); - } - -} diff --git a/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java b/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java index e611353..5fa2efa 100644 --- a/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java +++ b/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java @@ -9,7 +9,7 @@ import com.pengrad.telegrambot.request.GetMe; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import static cc.sukazyo.cono.morny.Logger.logger; +import static cc.sukazyo.cono.morny.Log.logger; /** * Morny Cono 核心
diff --git a/src/main/java/cc/sukazyo/cono/morny/ServerMain.java b/src/main/java/cc/sukazyo/cono/morny/ServerMain.java index f18487d..9cd9520 100644 --- a/src/main/java/cc/sukazyo/cono/morny/ServerMain.java +++ b/src/main/java/cc/sukazyo/cono/morny/ServerMain.java @@ -7,7 +7,7 @@ import java.time.ZoneId; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; -import static cc.sukazyo.cono.morny.Logger.logger; +import static cc.sukazyo.cono.morny.Log.logger; /** * 程序启动入口
diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/api/EventListenerManager.java b/src/main/java/cc/sukazyo/cono/morny/bot/api/EventListenerManager.java index 483b492..343de29 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/api/EventListenerManager.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/api/EventListenerManager.java @@ -8,7 +8,7 @@ import java.util.Arrays; import java.util.List; import java.util.function.Function; -import static cc.sukazyo.cono.morny.Logger.logger; +import static cc.sukazyo.cono.morny.Log.logger; public class EventListenerManager { diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java index 012c56a..e9609df 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java @@ -20,7 +20,7 @@ import java.time.ZoneId; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; -import static cc.sukazyo.cono.morny.Logger.logger; +import static cc.sukazyo.cono.morny.Log.logger; public class OnCommandExecute extends EventListener { @@ -101,12 +101,12 @@ public class OnCommandExecute extends EventListener { event.message().chat().id(), String.format(""" version: - %s + - %s core md5_hash: - %s + - %s compile timestamp: - %d - %s [UTC]""", + - %d + - %s [UTC]""", MornySystem.VERSION, MornySystem.getJarMd5(), GradleProjectConfigures.COMPILE_TIMESTAMP, diff --git a/src/main/java/cc/sukazyo/cono/morny/data/tracker/TrackerDataManager.java b/src/main/java/cc/sukazyo/cono/morny/data/tracker/TrackerDataManager.java index 048df3c..753944d 100644 --- a/src/main/java/cc/sukazyo/cono/morny/data/tracker/TrackerDataManager.java +++ b/src/main/java/cc/sukazyo/cono/morny/data/tracker/TrackerDataManager.java @@ -10,7 +10,7 @@ import java.util.HashMap; import java.util.TreeSet; import java.util.concurrent.locks.ReentrantLock; -import static cc.sukazyo.cono.morny.Logger.logger; +import static cc.sukazyo.cono.morny.Log.logger; public class TrackerDataManager {