多行log优化,开屏字符画输出,登录错误捕获

This commit is contained in:
A.C.Sukazyo Eyre 2021-11-07 17:07:16 +08:00
parent 928359034a
commit 703ef816c6
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
5 changed files with 38 additions and 12 deletions

View File

@ -3,7 +3,7 @@ plugins {
}
group 'cc.sukazyo'
version '0.1.1'
version '0.1.2'
repositories {
mavenCentral()

View File

@ -1,5 +1,7 @@
package cc.sukazyo.cono.morny;
import cc.sukazyo.cono.morny.util.StringUtils;
public class Logger {
public static final Logger logger = new Logger();
@ -16,15 +18,15 @@ public class Logger {
System.out.println(formatMessage(message, "WARN"));
}
public void error (String message) {
System.out.println(formatMessage(message, "ERRO"));
}
private String formatMessage (String message, String level) {
String levelStr = "\n["+level+"]";
return String.format(
"[%d][%s][%s]%s",
System.currentTimeMillis(),
Thread.currentThread().getName(),
level,
message.replaceAll("\\n", levelStr)
);
String prompt = String.format("[%s][%s]", System.currentTimeMillis(), Thread.currentThread().getName());
String levelStr = String.format("[%s]", level);
String newline = "\n" + StringUtils.repeatChar('\'', prompt.length()) + levelStr;
return prompt + levelStr + message.replaceAll("\\n", newline);
}
}

View File

@ -2,6 +2,7 @@ package cc.sukazyo.cono.morny;
import cc.sukazyo.cono.morny.bot.api.OnUpdate;
import cc.sukazyo.cono.morny.bot.event.EventListeners;
import cc.sukazyo.cono.morny.data.MornyHello;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.request.GetMe;
@ -13,11 +14,13 @@ public class MornyCoeur {
public static void main (String[] args) {
logger.info(MornyHello.MORNY_PREVIEW_IMAGE_ASCII);
logger.info("System Starting");
logger.info("args key: " + args[0]);
logger.info("args key:\n " + args[0]);
account = login(args[0]);
try { account = login(args[0]); }
catch (Exception e) { logger.error("Cannot login to bot/api."); System.exit(-1); }
logger.info("Bot login succeed.");
@ -38,7 +41,7 @@ public class MornyCoeur {
return account;
} catch (Exception e) {
e.printStackTrace(System.out);
logger.info("login failed.");
logger.error("login failed.");
}
}
throw new RuntimeException("Login failed..");

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,13 @@
package cc.sukazyo.cono.morny.util;
import java.util.Arrays;
public class StringUtils {
public static String repeatChar (char c, int i) {
char[] chars = new char[i];
Arrays.fill(chars, c);
return new String(chars);
}
}