mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Изменена система выводов логгирования
This commit is contained in:
parent
ef1f7b0e76
commit
ca0e8c0299
5 changed files with 96 additions and 19 deletions
|
@ -576,9 +576,9 @@ private void generateConfigIfNotExists() throws IOException {
|
|||
newConfig.isWarningMissArchJava = true;
|
||||
|
||||
// Set server address
|
||||
LogHelper.println("LaunchServer address: ");
|
||||
System.out.println("LaunchServer address: ");
|
||||
newConfig.setAddress(commandHandler.readLine());
|
||||
LogHelper.println("LaunchServer projectName: ");
|
||||
System.out.println("LaunchServer projectName: ");
|
||||
newConfig.setProjectName(commandHandler.readLine());
|
||||
|
||||
// Write LaunchServer config
|
||||
|
|
|
@ -32,7 +32,7 @@ public JLineCommandHandler(LaunchServer server) throws IOException {
|
|||
|
||||
// Replace writer
|
||||
LogHelper.removeStdOutput();
|
||||
LogHelper.addOutput(new JLineOutput());
|
||||
LogHelper.addOutput(new JLineOutput(), LogHelper.OutputTypes.JANSI);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,7 +30,7 @@ public void reply() throws Exception {
|
|||
LogHelper.error(e);
|
||||
}
|
||||
};
|
||||
LogHelper.addOutput(loutput);
|
||||
LogHelper.addOutput(loutput, LogHelper.OutputTypes.PLAIN);
|
||||
try {
|
||||
server.commandHandler.eval(cmd, false);
|
||||
output.writeBoolean(false);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class AddLogListenerResponse implements JsonResponseInterface {
|
||||
public LogHelper.OutputTypes outputType = LogHelper.OutputTypes.PLAIN;
|
||||
@Override
|
||||
public String getType() {
|
||||
return "addLogListener";
|
||||
|
@ -43,7 +44,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
}
|
||||
};
|
||||
client.logOutput = output;
|
||||
LogHelper.addOutput(output);
|
||||
LogHelper.addOutput(output, outputType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,21 +35,39 @@ public final class LogHelper {
|
|||
private static final AtomicBoolean DEBUG_ENABLED = new AtomicBoolean(Boolean.getBoolean(DEBUG_PROPERTY));
|
||||
private static final AtomicBoolean STACKTRACE_ENABLED = new AtomicBoolean(Boolean.getBoolean(STACKTRACE_PROPERTY));
|
||||
private static final AtomicBoolean DEV_ENABLED = new AtomicBoolean(Boolean.getBoolean(DEV_PROPERTY));
|
||||
private static final Set<Output> OUTPUTS = Collections.newSetFromMap(new ConcurrentHashMap<>(2));
|
||||
public static class OutputEnity
|
||||
{
|
||||
public Output output;
|
||||
public OutputTypes type;
|
||||
|
||||
public OutputEnity(Output output, OutputTypes type) {
|
||||
this.output = output;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
public enum OutputTypes
|
||||
{
|
||||
PLAIN, JANSI, HTML
|
||||
}
|
||||
private static final Set<OutputEnity> OUTPUTS = Collections.newSetFromMap(new ConcurrentHashMap<>(2));
|
||||
private static final Output STD_OUTPUT;
|
||||
|
||||
private LogHelper() {
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void addOutput(Output output) {
|
||||
public static void addOutput(OutputEnity output) {
|
||||
OUTPUTS.add(Objects.requireNonNull(output, "output"));
|
||||
}
|
||||
@LauncherAPI
|
||||
public static void addOutput(Output output, OutputTypes type) {
|
||||
OUTPUTS.add(new OutputEnity(Objects.requireNonNull(output, "output"),type));
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void addOutput(Path file) throws IOException {
|
||||
if (JANSI) {
|
||||
addOutput(new JAnsiOutput(IOHelper.newOutput(file, true)));
|
||||
addOutput(new JAnsiOutput(IOHelper.newOutput(file, true)),OutputTypes.JANSI);
|
||||
} else {
|
||||
addOutput(IOHelper.newWriter(file, true));
|
||||
}
|
||||
|
@ -57,7 +75,7 @@ public static void addOutput(Path file) throws IOException {
|
|||
|
||||
@LauncherAPI
|
||||
public static void addOutput(Writer writer) {
|
||||
addOutput(new WriterOutput(writer));
|
||||
addOutput(new WriterOutput(writer), OutputTypes.PLAIN);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
@ -142,24 +160,82 @@ public static void setDevEnabled(boolean stacktraceEnabled) {
|
|||
@LauncherAPI
|
||||
public static void log(Level level, String message, boolean sub) {
|
||||
String dateTime = DATE_TIME_FORMATTER.format(LocalDateTime.now());
|
||||
println(JANSI ? ansiFormatLog(level, dateTime, message, sub) :
|
||||
formatLog(level, message, dateTime, sub));
|
||||
String jansiString = null, plainString = null;
|
||||
for (OutputEnity output : OUTPUTS) {
|
||||
if(output.type == OutputTypes.JANSI && JANSI)
|
||||
{
|
||||
if(jansiString != null){
|
||||
output.output.println(jansiString);
|
||||
continue;
|
||||
}
|
||||
|
||||
jansiString = ansiFormatLog(level, dateTime, message, sub);
|
||||
output.output.println(jansiString);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(plainString != null){
|
||||
output.output.println(plainString);
|
||||
continue;
|
||||
}
|
||||
|
||||
plainString = formatLog(level, message, dateTime, sub);
|
||||
output.output.println(plainString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void printVersion(String product) {
|
||||
println(JANSI ? ansiFormatVersion(product) : formatVersion(product));
|
||||
String jansiString = null, plainString = null;
|
||||
for (OutputEnity output : OUTPUTS) {
|
||||
if(output.type == OutputTypes.JANSI && JANSI)
|
||||
{
|
||||
if(jansiString != null){
|
||||
output.output.println(jansiString);
|
||||
continue;
|
||||
}
|
||||
|
||||
jansiString = ansiFormatVersion(product);
|
||||
output.output.println(jansiString);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(plainString != null){
|
||||
output.output.println(plainString);
|
||||
continue;
|
||||
}
|
||||
|
||||
plainString = formatVersion(product);
|
||||
output.output.println(plainString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void printLicense(String product) {
|
||||
println(JANSI ? ansiFormatLicense(product) : formatLicense(product));
|
||||
String jansiString = null, plainString = null;
|
||||
for (OutputEnity output : OUTPUTS) {
|
||||
if(output.type == OutputTypes.JANSI && JANSI)
|
||||
{
|
||||
if(jansiString != null){
|
||||
output.output.println(jansiString);
|
||||
continue;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static synchronized void println(String message) {
|
||||
for (Output output : OUTPUTS) {
|
||||
output.println(message);
|
||||
jansiString = ansiFormatLicense(product);
|
||||
output.output.println(jansiString);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(plainString != null){
|
||||
output.output.println(plainString);
|
||||
continue;
|
||||
}
|
||||
|
||||
plainString = formatLicense(product);
|
||||
output.output.println(plainString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,7 +398,7 @@ private static String formatLicense(String product) {
|
|||
|
||||
// Add std writer
|
||||
STD_OUTPUT = System.out::println;
|
||||
addOutput(STD_OUTPUT);
|
||||
addOutput(STD_OUTPUT, JANSI ? OutputTypes.JANSI : OutputTypes.PLAIN);
|
||||
|
||||
// Add file log writer
|
||||
String logFile = System.getProperty("launcher.logFile");
|
||||
|
|
Loading…
Reference in a new issue