mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Реализация вывода логов в HTML
This commit is contained in:
parent
31b9d43a7f
commit
9bdde2a727
3 changed files with 50 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
package ru.gravit.launchserver.console;
|
package ru.gravit.launchserver.console;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.LauncherNetworkAPI;
|
||||||
import ru.gravit.launcher.events.request.LogEvent;
|
import ru.gravit.launcher.events.request.LogEvent;
|
||||||
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
|
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
|
||||||
import ru.gravit.launcher.request.websockets.RequestInterface;
|
import ru.gravit.launcher.request.websockets.RequestInterface;
|
||||||
|
@ -9,6 +10,13 @@
|
||||||
public class LogListenerCommand extends Command {
|
public class LogListenerCommand extends Command {
|
||||||
public class LogListenerRequest implements RequestInterface
|
public class LogListenerRequest implements RequestInterface
|
||||||
{
|
{
|
||||||
|
@LauncherNetworkAPI
|
||||||
|
public LogHelper.OutputTypes outputType;
|
||||||
|
|
||||||
|
public LogListenerRequest(LogHelper.OutputTypes outputType) {
|
||||||
|
this.outputType = outputType;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return "addLogListener";
|
return "addLogListener";
|
||||||
|
@ -27,7 +35,7 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
LogHelper.info("Send log listener request");
|
LogHelper.info("Send log listener request");
|
||||||
LegacyRequestBridge.service.sendObject(new LogListenerRequest());
|
LegacyRequestBridge.service.sendObject(new LogListenerRequest(LogHelper.JANSI ? LogHelper.OutputTypes.JANSI : LogHelper.OutputTypes.PLAIN));
|
||||||
LogHelper.info("Add log handler");
|
LogHelper.info("Add log handler");
|
||||||
LegacyRequestBridge.service.registerHandler((result) -> {
|
LegacyRequestBridge.service.registerHandler((result) -> {
|
||||||
if(result instanceof LogEvent)
|
if(result instanceof LogEvent)
|
||||||
|
|
|
@ -26,7 +26,7 @@ private static void printCommand(String name, Command command) {
|
||||||
ansi.a(command.getUsageDescription());
|
ansi.a(command.getUsageDescription());
|
||||||
ansi.reset();
|
ansi.reset();
|
||||||
return ansi.toString();
|
return ansi.toString();
|
||||||
});
|
}, () -> LogHelper.htmlFormatLog(LogHelper.Level.INFO, LogHelper.getDataTime(), String.format("<font color=\"green\">%s</font> <font color=\"cyan\">%s</font> - <font color=\"yellow\">%s</font>", name, args == null ? "[nothing]" : args, command.getUsageDescription()), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void printCategory(String name, String description)
|
private static void printCategory(String name, String description)
|
||||||
|
|
|
@ -168,7 +168,7 @@ public static String getDataTime()
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static void log(Level level, String message, boolean sub) {
|
public static void log(Level level, String message, boolean sub) {
|
||||||
String dateTime = DATE_TIME_FORMATTER.format(LocalDateTime.now());
|
String dateTime = DATE_TIME_FORMATTER.format(LocalDateTime.now());
|
||||||
String jansiString = null, plainString = null;
|
String jansiString = null, plainString = null, htmlString = null;
|
||||||
for (OutputEnity output : OUTPUTS) {
|
for (OutputEnity output : OUTPUTS) {
|
||||||
if (output.type == OutputTypes.JANSI && JANSI) {
|
if (output.type == OutputTypes.JANSI && JANSI) {
|
||||||
if (jansiString != null) {
|
if (jansiString != null) {
|
||||||
|
@ -178,6 +178,14 @@ public static void log(Level level, String message, boolean sub) {
|
||||||
|
|
||||||
jansiString = ansiFormatLog(level, dateTime, message, sub);
|
jansiString = ansiFormatLog(level, dateTime, message, sub);
|
||||||
output.output.println(jansiString);
|
output.output.println(jansiString);
|
||||||
|
} else if (output.type == OutputTypes.HTML) {
|
||||||
|
if (htmlString != null) {
|
||||||
|
output.output.println(htmlString);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
htmlString = htmlFormatLog(level, dateTime, message, sub);
|
||||||
|
output.output.println(htmlString);
|
||||||
} else {
|
} else {
|
||||||
if (plainString != null) {
|
if (plainString != null) {
|
||||||
output.output.println(plainString);
|
output.output.println(plainString);
|
||||||
|
@ -192,7 +200,12 @@ public static void log(Level level, String message, boolean sub) {
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static void rawLog(Supplier<String> plainStr, Supplier<String> jansiStr)
|
public static void rawLog(Supplier<String> plainStr, Supplier<String> jansiStr)
|
||||||
{
|
{
|
||||||
String jansiString = null, plainString = null;
|
rawLog(plainStr, jansiStr, null);
|
||||||
|
}
|
||||||
|
@LauncherAPI
|
||||||
|
public static void rawLog(Supplier<String> plainStr, Supplier<String> jansiStr, Supplier<String> htmlStr)
|
||||||
|
{
|
||||||
|
String jansiString = null, plainString = null, htmlString = null;
|
||||||
for (OutputEnity output : OUTPUTS) {
|
for (OutputEnity output : OUTPUTS) {
|
||||||
if (output.type == OutputTypes.JANSI && JANSI) {
|
if (output.type == OutputTypes.JANSI && JANSI) {
|
||||||
if (jansiString != null) {
|
if (jansiString != null) {
|
||||||
|
@ -202,6 +215,14 @@ public static void rawLog(Supplier<String> plainStr, Supplier<String> jansiStr)
|
||||||
|
|
||||||
jansiString = jansiStr.get();
|
jansiString = jansiStr.get();
|
||||||
output.output.println(jansiString);
|
output.output.println(jansiString);
|
||||||
|
} else if (output.type == OutputTypes.HTML) {
|
||||||
|
if (htmlString != null) {
|
||||||
|
output.output.println(htmlString);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
htmlString = htmlStr.get();
|
||||||
|
output.output.println(htmlString);
|
||||||
} else {
|
} else {
|
||||||
if (plainString != null) {
|
if (plainString != null) {
|
||||||
output.output.println(plainString);
|
output.output.println(plainString);
|
||||||
|
@ -377,6 +398,23 @@ public static Ansi rawAnsiFormat(Level level, String dateTime, boolean sub)
|
||||||
return ansi;
|
return ansi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String htmlFormatLog(Level level, String dateTime, String message, boolean sub)
|
||||||
|
{
|
||||||
|
String levelColor;
|
||||||
|
switch (level) {
|
||||||
|
case WARNING:
|
||||||
|
levelColor = "yellow";
|
||||||
|
break;
|
||||||
|
case ERROR:
|
||||||
|
levelColor = "red";
|
||||||
|
break;
|
||||||
|
default: // INFO, DEBUG, Unknown
|
||||||
|
levelColor = "white";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return String.format("%s <b><font color=\"%s\">[%s] %s</font></b>", dateTime, levelColor, level.toString(), sub ? ' ' + message : message);
|
||||||
|
}
|
||||||
|
|
||||||
private static String ansiFormatVersion(String product) {
|
private static String ansiFormatVersion(String product) {
|
||||||
return new Ansi().bold(). // Setup
|
return new Ansi().bold(). // Setup
|
||||||
fgBright(Color.MAGENTA).a("GravitLauncher "). // sashok724's
|
fgBright(Color.MAGENTA).a("GravitLauncher "). // sashok724's
|
||||||
|
|
Loading…
Reference in a new issue