Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 16:12:46 +01:00
Attempt to get log4j2 working
Dieser Commit ist enthalten in:
Ursprung
f9a1656b8e
Commit
e52a461a73
@ -20,27 +20,55 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.minecrell</groupId>
|
<groupId>net.minecrell</groupId>
|
||||||
<artifactId>terminalconsoleappender</artifactId>
|
<artifactId>terminalconsoleappender</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.1.1</version>
|
||||||
<type>jar</type>
|
<exclusions>
|
||||||
<scope>compile</scope>
|
<exclusion>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.jline</groupId>
|
||||||
|
<artifactId>jline-reader</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.jline</groupId>
|
||||||
|
<artifactId>jline-terminal-jna</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.jline</groupId>
|
||||||
|
<artifactId>jline-terminal</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.jline</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>jline-terminal</artifactId>
|
||||||
<version>1.7.5</version>
|
<version>3.9.0</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.jline</groupId>
|
||||||
<artifactId>slf4j-simple</artifactId>
|
<artifactId>jline-terminal-jna</artifactId>
|
||||||
<version>1.6.4</version>
|
<version>3.9.0</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.fusesource.jansi</groupId>
|
<groupId>org.jline</groupId>
|
||||||
<artifactId>jansi</artifactId>
|
<artifactId>jline-reader</artifactId>
|
||||||
<version>1.18</version>
|
<version>3.9.0</version>
|
||||||
<scope>compile</scope>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-api</artifactId>
|
||||||
|
<version>2.13.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<version>2.13.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-slf4j18-impl</artifactId>
|
||||||
|
<version>2.13.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
|
@ -25,12 +25,10 @@
|
|||||||
|
|
||||||
package org.geysermc.platform.standalone;
|
package org.geysermc.platform.standalone;
|
||||||
|
|
||||||
import org.fusesource.jansi.AnsiConsole;
|
|
||||||
import org.geysermc.common.PlatformType;
|
import org.geysermc.common.PlatformType;
|
||||||
import org.geysermc.common.bootstrap.IGeyserBootstrap;
|
import org.geysermc.common.bootstrap.IGeyserBootstrap;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.utils.FileUtils;
|
import org.geysermc.connector.utils.FileUtils;
|
||||||
import org.geysermc.platform.standalone.console.ConsoleCommandReader;
|
|
||||||
import org.geysermc.platform.standalone.console.GeyserLogger;
|
import org.geysermc.platform.standalone.console.GeyserLogger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -48,11 +46,6 @@ public class GeyserBootstrap implements IGeyserBootstrap {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Metric
|
|
||||||
if (!(System.console() == null) && System.getProperty("os.name", "Windows 10").toLowerCase().contains("windows")) {
|
|
||||||
AnsiConsole.systemInstall();
|
|
||||||
}
|
|
||||||
|
|
||||||
geyserLogger = new GeyserLogger();
|
geyserLogger = new GeyserLogger();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -63,10 +56,8 @@ public class GeyserBootstrap implements IGeyserBootstrap {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
GeyserConnector connector = GeyserConnector.start(PlatformType.STANDALONE, this);
|
GeyserConnector.start(PlatformType.STANDALONE, this);
|
||||||
|
geyserLogger.start();
|
||||||
ConsoleCommandReader consoleReader = new ConsoleCommandReader(connector);
|
|
||||||
consoleReader.startConsole();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* @author GeyserMC
|
|
||||||
* @link https://github.com/GeyserMC/Geyser
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.geysermc.platform.standalone.console;
|
|
||||||
|
|
||||||
import net.minecrell.terminalconsole.TerminalConsoleAppender;
|
|
||||||
|
|
||||||
import org.geysermc.connector.GeyserConnector;
|
|
||||||
import org.geysermc.connector.command.GeyserConsoleCommandSender;
|
|
||||||
import org.jline.reader.EndOfFileException;
|
|
||||||
import org.jline.reader.LineReader;
|
|
||||||
import org.jline.reader.LineReaderBuilder;
|
|
||||||
import org.jline.reader.UserInterruptException;
|
|
||||||
import org.jline.terminal.Terminal;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public class ConsoleCommandReader {
|
|
||||||
|
|
||||||
private GeyserConnector connector;
|
|
||||||
private Terminal terminal;
|
|
||||||
|
|
||||||
public ConsoleCommandReader(GeyserConnector connector) {
|
|
||||||
this.connector = connector;
|
|
||||||
this.terminal = TerminalConsoleAppender.getTerminal();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startConsole() {
|
|
||||||
Thread thread = new Thread(() -> {
|
|
||||||
if (terminal != null) {
|
|
||||||
LineReader lineReader = LineReaderBuilder.builder()
|
|
||||||
.appName("Geyser")
|
|
||||||
.terminal(terminal)
|
|
||||||
.build();
|
|
||||||
TerminalConsoleAppender.setReader(lineReader);
|
|
||||||
|
|
||||||
try {
|
|
||||||
String line;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
line = lineReader.readLine("> ");
|
|
||||||
} catch (EndOfFileException ignored) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line == null)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (UserInterruptException ignore) {
|
|
||||||
/* do nothing */
|
|
||||||
} finally {
|
|
||||||
TerminalConsoleAppender.setReader(null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
GeyserConsoleCommandSender sender = new GeyserConsoleCommandSender();
|
|
||||||
connector.getCommandMap().runCommand(sender, line);
|
|
||||||
}
|
|
||||||
} catch (IOException ex) {
|
|
||||||
Logger.getLogger("Geyser").log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
thread.setName("ConsoleCommandThread");
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,15 +27,22 @@ package org.geysermc.platform.standalone.console;
|
|||||||
|
|
||||||
import io.sentry.Sentry;
|
import io.sentry.Sentry;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
import net.minecrell.terminalconsole.SimpleTerminalConsole;
|
||||||
|
|
||||||
import org.geysermc.common.ChatColor;
|
import org.geysermc.common.ChatColor;
|
||||||
import org.geysermc.common.logger.IGeyserLogger;
|
import org.geysermc.common.logger.IGeyserLogger;
|
||||||
|
import org.geysermc.connector.GeyserConnector;
|
||||||
|
import org.geysermc.connector.command.GeyserConsoleCommandSender;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
public class GeyserLogger implements IGeyserLogger {
|
@Log4j2
|
||||||
|
public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger {
|
||||||
|
|
||||||
private boolean colored = true;
|
private boolean colored = true;
|
||||||
private boolean debug = false;
|
private boolean debug = false;
|
||||||
@ -88,40 +95,56 @@ public class GeyserLogger implements IGeyserLogger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isRunning() {
|
||||||
|
return !GeyserConnector.getInstance().isShuttingDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void runCommand(String line) {
|
||||||
|
GeyserConsoleCommandSender sender = new GeyserConsoleCommandSender();
|
||||||
|
GeyserConnector.getInstance().getCommandMap().runCommand(sender, line);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void shutdown() {
|
||||||
|
GeyserConnector.getInstance().shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void severe(String message) {
|
public void severe(String message) {
|
||||||
System.out.println(printConsole(ChatColor.DARK_RED + message, colored));
|
log.fatal(printConsole(ChatColor.DARK_RED + message, colored));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void severe(String message, Throwable error) {
|
public void severe(String message, Throwable error) {
|
||||||
System.out.println(printConsole(ChatColor.DARK_RED + message + "\n" + error.getMessage(), colored));
|
log.fatal(printConsole(ChatColor.DARK_RED + message, colored), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(String message) {
|
public void error(String message) {
|
||||||
System.out.println(printConsole(ChatColor.RED + message, colored));
|
log.error(printConsole(ChatColor.RED + message, colored));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(String message, Throwable error) {
|
public void error(String message, Throwable error) {
|
||||||
System.out.println(printConsole(ChatColor.RED + message + "\n" + error, colored));
|
log.error(printConsole(ChatColor.RED + message, colored), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void warning(String message) {
|
public void warning(String message) {
|
||||||
System.out.println(printConsole(ChatColor.YELLOW + message, colored));
|
log.warn(printConsole(ChatColor.YELLOW + message, colored));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void info(String message) {
|
public void info(String message) {
|
||||||
System.out.println(printConsole(ChatColor.WHITE + message, colored));
|
log.info(printConsole(ChatColor.WHITE + message, colored));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void debug(String message) {
|
public void debug(String message) {
|
||||||
if (debug)
|
if (debug)
|
||||||
System.out.println(printConsole(ChatColor.GRAY + message, colored));
|
log.info(printConsole(ChatColor.GRAY + message, colored));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String printConsole(String message, boolean colors) {
|
public static String printConsole(String message, boolean colors) {
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
log4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
|
20
bootstrap/standalone/src/main/resources/log4j2.yml
Normale Datei
20
bootstrap/standalone/src/main/resources/log4j2.yml
Normale Datei
@ -0,0 +1,20 @@
|
|||||||
|
Configuration:
|
||||||
|
Appenders:
|
||||||
|
TerminalConsole:
|
||||||
|
PatternLayout:
|
||||||
|
pattern: "%cyan{%d{HH:mm:ss}} [%style{%highlight{%-5level}{STYLE=Logback}}] %minecraftFormatting{%msg}%n"
|
||||||
|
name: Console
|
||||||
|
RollingRandomAccessFile:
|
||||||
|
PatternLayout:
|
||||||
|
pattern: "%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level - %msg%n"
|
||||||
|
Policies:
|
||||||
|
TimeBasedTriggeringPolicy: ""
|
||||||
|
OnStartupTriggeringPolicy: ""
|
||||||
|
name: File
|
||||||
|
fileName: "logs/server.log"
|
||||||
|
filePattern: "logs/%d{yyyy-MM-dd}-%i.log.gz"
|
||||||
|
Loggers:
|
||||||
|
Root:
|
||||||
|
level: error
|
||||||
|
AppenderRef:
|
||||||
|
ref: Console
|
@ -57,7 +57,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.steveice10</groupId>
|
<groupId>com.github.steveice10</groupId>
|
||||||
<artifactId>packetlib</artifactId>
|
<artifactId>packetlib</artifactId>
|
||||||
<version>1.4-SNAPSHOT</version>
|
<version>1.5-SNAPSHOT</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren