mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 03:04:54 +08:00
引入 messiva 作为 log 系统,规范了 version 命令的返回格式
This commit is contained in:
parent
dc332de50c
commit
ecef73fad4
@ -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}"
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
14
src/main/java/cc/sukazyo/cono/morny/Log.java
Normal file
14
src/main/java/cc/sukazyo/cono/morny/Log.java
Normal file
@ -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());
|
||||
|
||||
}
|
@ -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 消息<br>
|
||||
* {@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"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将传入的消息和消息元数据重新整理为固定格式<br>
|
||||
* <br>
|
||||
* 这个方法会{@link System#currentTimeMillis() 获取当前时间}和{@link Thread#currentThread() 当前线程}的名称,
|
||||
* 然后将数据整理为 {@code [<timestamp>][<thread-name>][<level>]<data>} 格式。<br>
|
||||
* 如果消息是多行的,则每行的开头都会被加入 {@code [<timestamp>][<thread-name>][<level>]} 这样的前缀,
|
||||
* 不过,前缀中 {@code [<timestamp>][<thread-name>]} 会被转换为等长的 {@code '} 字串。
|
||||
* <br>
|
||||
* 最终的 format 格式将会类似于以下的模样:<pre><code>
|
||||
[1019284827][EVT388223][INFO]Something message got:
|
||||
'''''''''''''''''''''''[INFO] - data source: 19773
|
||||
'''''''''''''''''''''''[INFO] - message raw: noh2q0jwd9j-jn-9jq92-ed
|
||||
* </code></pre>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
}
|
@ -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 核心<br>
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
* 程序启动入口<br>
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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:
|
||||
<code> </code><code>%s</code>
|
||||
- <code>%s</code>
|
||||
core md5_hash:
|
||||
<code> </code><code>%s</code>
|
||||
- <code>%s</code>
|
||||
compile timestamp:
|
||||
<code> </code><code>%d</code>
|
||||
<code> </code><code>%s [UTC]</code>""",
|
||||
- <code>%d</code>
|
||||
- <code>%s [UTC]</code>""",
|
||||
MornySystem.VERSION,
|
||||
MornySystem.getJarMd5(),
|
||||
GradleProjectConfigures.COMPILE_TIMESTAMP,
|
||||
|
@ -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 {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user