geforkt von Mirrors/Velocity
Switch to log4j2 logging
Dieser Commit ist enthalten in:
Ursprung
ae6adf0ca1
Commit
c9af231c7e
3
.gitignore
vendored
3
.gitignore
vendored
@ -118,3 +118,6 @@ gradle-app.setting
|
||||
|
||||
|
||||
# End of https://www.gitignore.io/api/java,gradle,intellij
|
||||
|
||||
# Other trash
|
||||
logs/
|
@ -25,6 +25,8 @@ dependencies {
|
||||
compile "io.netty:netty-transport-native-epoll:${nettyVersion}"
|
||||
compile "io.netty:netty-transport-native-epoll:${nettyVersion}:linux-x86_64"
|
||||
compile 'net.kyori:text:1.12-1.5.0'
|
||||
compile 'org.apache.logging.log4j:log4j-api:2.11.0'
|
||||
compile 'org.apache.logging.log4j:log4j-core:2.11.0'
|
||||
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.0-M1'
|
||||
testCompile 'org.junit.jupiter:junit-jupiter-engine:5.3.0-M1'
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
@ -45,6 +47,8 @@ import static com.velocitypowered.network.Connections.MINECRAFT_ENCODER;
|
||||
import static com.velocitypowered.network.Connections.READ_TIMEOUT;
|
||||
|
||||
public final class ConnectionManager {
|
||||
private static final org.apache.logging.log4j.Logger logger = LogManager.getLogger(ConnectionManager.class);
|
||||
|
||||
private static final String DISABLE_EPOLL_PROPERTY = "velocity.connection.disable-epoll";
|
||||
private static final boolean DISABLE_EPOLL = Boolean.getBoolean(DISABLE_EPOLL_PROPERTY);
|
||||
private final Set<Channel> endpoints = new HashSet<>();
|
||||
@ -71,12 +75,12 @@ public final class ConnectionManager {
|
||||
|
||||
private void logChannelInformation(final boolean epoll) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("Channel type: ");
|
||||
sb.append("Using channel type ");
|
||||
sb.append(epoll ? "epoll": "nio");
|
||||
if(DISABLE_EPOLL) {
|
||||
sb.append(String.format(" - epoll explicitly disabled using -D%s=true", DISABLE_EPOLL_PROPERTY));
|
||||
}
|
||||
System.out.println(sb.toString()); // TODO: move to logger
|
||||
logger.info(sb.toString()); // TODO: move to logger
|
||||
}
|
||||
|
||||
public void bind(final InetSocketAddress address) {
|
||||
@ -109,10 +113,9 @@ public final class ConnectionManager {
|
||||
final Channel channel = future.channel();
|
||||
if (future.isSuccess()) {
|
||||
this.endpoints.add(channel);
|
||||
System.out.println("Listening on " + channel.localAddress()); // TODO: move to logger
|
||||
logger.info("Listening on {}", channel.localAddress());
|
||||
} else {
|
||||
System.out.println("Can't bind to " + channel.localAddress()); // TODO: move to logger
|
||||
future.cause().printStackTrace();
|
||||
logger.error("Can't bind to {}", address, future.cause());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -126,11 +129,10 @@ public final class ConnectionManager {
|
||||
public void shutdown() {
|
||||
for (final Channel endpoint : this.endpoints) {
|
||||
try {
|
||||
System.out.println(String.format("Closing endpoint %s", endpoint.localAddress())); // TODO: move to logger
|
||||
logger.info("Closing endpoint {}", endpoint.localAddress());
|
||||
endpoint.close().sync();
|
||||
} catch (final InterruptedException e) {
|
||||
System.err.println("Interrupted whilst closing endpoint"); // TODO: move to logger
|
||||
e.printStackTrace();
|
||||
logger.info("Interrupted whilst closing endpoint", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ import com.velocitypowered.proxy.connection.backend.ServerConnection;
|
||||
import com.velocitypowered.proxy.data.ServerInfo;
|
||||
import com.velocitypowered.proxy.util.EncryptionUtils;
|
||||
import com.velocitypowered.proxy.util.UuidUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URL;
|
||||
@ -21,6 +23,8 @@ import java.util.Arrays;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
private static final Logger logger = LogManager.getLogger(LoginSessionHandler.class);
|
||||
|
||||
private static final String MOJANG_SERVER_AUTH_URL =
|
||||
"https://sessionserver.mojang.com/session/minecraft/hasJoined?username=%s&serverId=%s&ip=%s";
|
||||
|
||||
@ -71,8 +75,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
handleSuccessfulLogin(profile);
|
||||
}, inbound.getChannel().eventLoop())
|
||||
.exceptionally(exception -> {
|
||||
System.out.println("Can't enable encryption");
|
||||
exception.printStackTrace();
|
||||
logger.error("Unable to enable encryption", exception);
|
||||
inbound.close();
|
||||
return null;
|
||||
});
|
||||
|
23
src/main/resources/log4j2.xml
Normale Datei
23
src/main/resources/log4j2.xml
Normale Datei
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="warn">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n"/>
|
||||
</Console>
|
||||
<RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz"
|
||||
immediateFlush="false">
|
||||
<PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy/>
|
||||
<OnStartupTriggeringPolicy/>
|
||||
</Policies>
|
||||
</RollingRandomAccessFile>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<Root level="info">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="File"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren