Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-25 15:50:14 +01:00
Get log4j2 working and fix commands
Dieser Commit ist enthalten in:
Ursprung
e52a461a73
Commit
936cbad67d
@ -90,6 +90,13 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.edwgiz</groupId>
|
||||
<artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
|
||||
<version>2.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@ -97,10 +104,29 @@
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/versions/9/module-info.class</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>org.geysermc.platform.standalone.GeyserBootstrap</mainClass>
|
||||
</transformer>
|
||||
<transformer
|
||||
implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer">
|
||||
</transformer>
|
||||
</transformers>
|
||||
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
@ -25,75 +25,20 @@
|
||||
|
||||
package org.geysermc.platform.standalone.console;
|
||||
|
||||
import io.sentry.Sentry;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import net.minecrell.terminalconsole.SimpleTerminalConsole;
|
||||
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.geysermc.common.ChatColor;
|
||||
import org.geysermc.common.logger.IGeyserLogger;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.command.GeyserConsoleCommandSender;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.logging.*;
|
||||
import org.geysermc.connector.command.CommandSender;
|
||||
|
||||
@Log4j2
|
||||
public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger {
|
||||
public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger, CommandSender {
|
||||
|
||||
private boolean colored = true;
|
||||
private boolean debug = false;
|
||||
|
||||
public GeyserLogger() {
|
||||
ConsoleHandler consoleHandler = new ConsoleHandler();
|
||||
consoleHandler.setLevel(Level.INFO);
|
||||
consoleHandler.setFormatter(new SimpleFormatter() {
|
||||
private static final String format = "[%1$tT][%2$-5s] %3$s %n";
|
||||
|
||||
@Override
|
||||
public synchronized String format(LogRecord lr) {
|
||||
return String.format(format,
|
||||
new Date(lr.getMillis()),
|
||||
lr.getLevel().getLocalizedName(),
|
||||
lr.getMessage()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
File logDir = new File("logs");
|
||||
logDir.mkdir();
|
||||
File logFile = new File(logDir, "latest.log");
|
||||
int maxLogFileSize = 20;//Mo
|
||||
if (logFile.exists() && (logFile.length()) > maxLogFileSize * 1024L * 1024L)
|
||||
this.warning("Your log file is larger than " + maxLogFileSize + "Mo, you should backup and clean it !");
|
||||
FileHandler fileHandler = new FileHandler(logFile.getCanonicalPath(), true);
|
||||
fileHandler.setLevel(Level.INFO);
|
||||
fileHandler.setFormatter(new SimpleFormatter() {
|
||||
private static final String format = "[%1$tF %1$tT][%2$-5s] %3$s %n";
|
||||
|
||||
@Override
|
||||
public synchronized String format(LogRecord lr) {
|
||||
return String.format(format,
|
||||
new Date(lr.getMillis()),
|
||||
lr.getLevel().getLocalizedName(),
|
||||
lr.getMessage()
|
||||
);
|
||||
}
|
||||
});
|
||||
} catch (IOException | SecurityException ex) {
|
||||
Logger.getLogger(GeyserLogger.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
if (System.getenv().containsKey("DP_SENTRY_CLIENT_KEY")) {
|
||||
Handler sentryHandler = new io.sentry.jul.SentryHandler();
|
||||
sentryHandler.setLevel(Level.SEVERE);
|
||||
Sentry.init(System.getenv().get("DP_SENTRY_CLIENT_KEY"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRunning() {
|
||||
@ -102,8 +47,7 @@ public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger
|
||||
|
||||
@Override
|
||||
protected void runCommand(String line) {
|
||||
GeyserConsoleCommandSender sender = new GeyserConsoleCommandSender();
|
||||
GeyserConnector.getInstance().getCommandMap().runCommand(sender, line);
|
||||
GeyserConnector.getInstance().getCommandMap().runCommand(this, line);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -143,8 +87,7 @@ public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger
|
||||
|
||||
@Override
|
||||
public void debug(String message) {
|
||||
if (debug)
|
||||
log.info(printConsole(ChatColor.GRAY + message, colored));
|
||||
log.debug(printConsole(ChatColor.GRAY + message, colored));
|
||||
}
|
||||
|
||||
public static String printConsole(String message, boolean colors) {
|
||||
@ -153,6 +96,16 @@ public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger
|
||||
|
||||
@Override
|
||||
public void setDebug(boolean debug) {
|
||||
this.debug = debug;
|
||||
Configurator.setLevel(log.getName(), debug ? org.apache.logging.log4j.Level.DEBUG : log.getLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "CONSOLE";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
info(message);
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
log4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
|
21
bootstrap/standalone/src/main/resources/log4j2.xml
Normale Datei
21
bootstrap/standalone/src/main/resources/log4j2.xml
Normale Datei
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<TerminalConsole name="Console">
|
||||
<PatternLayout pattern="[%d{HH:mm:ss} %style{%highlight{%level}{FATAL=red dark, ERROR=red, WARN=yellow bright, INFO=cyan bright, DEBUG=green, TRACE=white}}] %minecraftFormatting{%msg}%n"/>
|
||||
</TerminalConsole>
|
||||
<RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
|
||||
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %level{length=1} - %msg%n"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy/>
|
||||
<OnStartupTriggeringPolicy/>
|
||||
</Policies>
|
||||
</RollingRandomAccessFile>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="INFO">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="File"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
@ -1,20 +0,0 @@
|
||||
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
|
@ -61,7 +61,7 @@ public class GeyserCommandMap {
|
||||
}
|
||||
|
||||
public void runCommand(CommandSender sender, String command) {
|
||||
if (!command.startsWith("/geyser "))
|
||||
if (!command.startsWith("geyser "))
|
||||
return;
|
||||
|
||||
command = command.trim();
|
||||
@ -80,7 +80,7 @@ public class GeyserCommandMap {
|
||||
|
||||
GeyserCommand cmd = commandMap.get(label);
|
||||
if (cmd == null) {
|
||||
connector.getLogger().warning("Invalid Command! Try /help for a list of commands.");
|
||||
connector.getLogger().error("Invalid Command! Try /geyser help for a list of commands.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,41 +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.connector.command;
|
||||
|
||||
import org.geysermc.common.ChatColor;
|
||||
|
||||
public class GeyserConsoleCommandSender implements CommandSender {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "CONSOLE";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
System.out.println(ChatColor.toANSI(message + ChatColor.RESET));
|
||||
}
|
||||
}
|
@ -52,7 +52,7 @@ public class HelpCommand extends GeyserCommand {
|
||||
Collections.sort(commands);
|
||||
|
||||
for (String cmd : commands) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "/" + cmd + ChatColor.WHITE + ": " + cmds.get(cmd).getDescription());
|
||||
sender.sendMessage(ChatColor.YELLOW + "/geyser " + cmd + ChatColor.WHITE + ": " + cmds.get(cmd).getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren