mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2025-07-09 11:30:13 +02:00
Added logback logging
This commit is contained in:
parent
6bbde1f578
commit
e9b6c888bc
10
README.md
10
README.md
@ -5,7 +5,7 @@ The main goal of this project is maximum simplicity with a minimum number of sen
|
|||||||
The limbo is empty; there is no ability to set a schematic building since this is not necessary.
|
The limbo is empty; there is no ability to set a schematic building since this is not necessary.
|
||||||
You can send useful information via chat or boss bar.
|
You can send useful information via chat or boss bar.
|
||||||
|
|
||||||
No plugins, no logs. The server is fully clear. It is only able keep a lot of players while the main server is down.
|
No plugins, no logs. The server is fully clear. It is only able to keep a lot of players while the main server is down.
|
||||||
|
|
||||||
General features:
|
General features:
|
||||||
* High performance. The server doesn't save or cache any useless (for limbo) data.
|
* High performance. The server doesn't save or cache any useless (for limbo) data.
|
||||||
@ -14,7 +14,7 @@ General features:
|
|||||||
* Support for [BungeeGuard](https://www.spigotmc.org/resources/79601/) handshake format.
|
* Support for [BungeeGuard](https://www.spigotmc.org/resources/79601/) handshake format.
|
||||||
* Multiple versions support.
|
* Multiple versions support.
|
||||||
* Fully configurable.
|
* Fully configurable.
|
||||||
* Lightweight. App size around **2MB**.
|
* Lightweight. App size around **3MB**.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@ -56,8 +56,8 @@ The installation process is simple.
|
|||||||
2. Put the jar file in the folder you want.
|
2. Put the jar file in the folder you want.
|
||||||
3. Create a start script as you did for Bukkit or BungeeCord, with a command like this:
|
3. Create a start script as you did for Bukkit or BungeeCord, with a command like this:
|
||||||
`java -jar NanoLimbo-<version>.jar`
|
`java -jar NanoLimbo-<version>.jar`
|
||||||
5. The server will create `settings.yml` file, which is the server configuration.
|
4. The server will create `settings.yml` file, which is the server configuration.
|
||||||
6. Configure it as you want and restart the server.
|
5. Configure it as you want and restart the server.
|
||||||
|
|
||||||
### Player info forwarding
|
### Player info forwarding
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ Then add your tokens to `tokens` list.
|
|||||||
|
|
||||||
### Contributing
|
### Contributing
|
||||||
|
|
||||||
Feel free to create a pull request if you found some bug or optimization opportunity, or if you want
|
Feel free to create a pull request if you find some bug or optimization opportunity, or if you want
|
||||||
to add some functionality that is suitable for a limbo server and won't significantly load the server.
|
to add some functionality that is suitable for a limbo server and won't significantly load the server.
|
||||||
|
|
||||||
### Building
|
### Building
|
||||||
|
@ -4,8 +4,8 @@ plugins {
|
|||||||
id 'com.github.gmazzo.buildconfig' version '3.1.0'
|
id 'com.github.gmazzo.buildconfig' version '3.1.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'ru.nanit'
|
group 'ua.nanit'
|
||||||
version '1.7'
|
version '1.8'
|
||||||
|
|
||||||
compileJava {
|
compileJava {
|
||||||
options.encoding = "UTF-8"
|
options.encoding = "UTF-8"
|
||||||
@ -24,6 +24,7 @@ dependencies {
|
|||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3'
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3'
|
||||||
|
|
||||||
|
implementation 'ch.qos.logback:logback-classic:1.5.6'
|
||||||
implementation 'org.spongepowered:configurate-yaml:4.1.2'
|
implementation 'org.spongepowered:configurate-yaml:4.1.2'
|
||||||
implementation 'io.netty:netty-all:4.1.101.Final'
|
implementation 'io.netty:netty-all:4.1.101.Final'
|
||||||
implementation 'net.kyori:adventure-nbt:4.14.0'
|
implementation 'net.kyori:adventure-nbt:4.14.0'
|
||||||
@ -44,7 +45,9 @@ shadowJar {
|
|||||||
attributes('Main-Class': 'ua.nanit.limbo.NanoLimbo')
|
attributes('Main-Class': 'ua.nanit.limbo.NanoLimbo')
|
||||||
}
|
}
|
||||||
|
|
||||||
minimize()
|
minimize {
|
||||||
|
exclude(dependency('ch.qos.logback:logback-classic:.*:.*'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
package ua.nanit.limbo;
|
package ua.nanit.limbo;
|
||||||
|
|
||||||
import ua.nanit.limbo.server.LimboServer;
|
import ua.nanit.limbo.server.LimboServer;
|
||||||
import ua.nanit.limbo.server.Logger;
|
import ua.nanit.limbo.server.Log;
|
||||||
|
|
||||||
public final class NanoLimbo {
|
public final class NanoLimbo {
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ public final class NanoLimbo {
|
|||||||
try {
|
try {
|
||||||
new LimboServer().start();
|
new LimboServer().start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.error("Cannot start server: ", e);
|
Log.error("Cannot start server: ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ import ua.nanit.limbo.protocol.packets.play.PacketKeepAlive;
|
|||||||
import ua.nanit.limbo.protocol.registry.State;
|
import ua.nanit.limbo.protocol.registry.State;
|
||||||
import ua.nanit.limbo.protocol.registry.Version;
|
import ua.nanit.limbo.protocol.registry.Version;
|
||||||
import ua.nanit.limbo.server.LimboServer;
|
import ua.nanit.limbo.server.LimboServer;
|
||||||
import ua.nanit.limbo.server.Logger;
|
import ua.nanit.limbo.server.Log;
|
||||||
import ua.nanit.limbo.util.UuidUtil;
|
import ua.nanit.limbo.util.UuidUtil;
|
||||||
|
|
||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
@ -104,7 +104,7 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||||
if (channel.isActive()) {
|
if (channel.isActive()) {
|
||||||
Logger.error("Unhandled exception: ", cause);
|
Log.error("Unhandled exception: ", cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
|||||||
setAddress(socketAddressHostname);
|
setAddress(socketAddressHostname);
|
||||||
gameProfile.setUuid(uuid);
|
gameProfile.setUuid(uuid);
|
||||||
|
|
||||||
Logger.debug("Successfully verified BungeeGuard token");
|
Log.debug("Successfully verified BungeeGuard token");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import ua.nanit.limbo.protocol.packets.status.PacketStatusPing;
|
|||||||
import ua.nanit.limbo.protocol.packets.status.PacketStatusRequest;
|
import ua.nanit.limbo.protocol.packets.status.PacketStatusRequest;
|
||||||
import ua.nanit.limbo.protocol.packets.status.PacketStatusResponse;
|
import ua.nanit.limbo.protocol.packets.status.PacketStatusResponse;
|
||||||
import ua.nanit.limbo.server.LimboServer;
|
import ua.nanit.limbo.server.LimboServer;
|
||||||
import ua.nanit.limbo.server.Logger;
|
import ua.nanit.limbo.server.Log;
|
||||||
import ua.nanit.limbo.util.UuidUtil;
|
import ua.nanit.limbo.util.UuidUtil;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
@ -46,7 +46,7 @@ public class PacketHandler {
|
|||||||
conn.updateVersion(packet.getVersion());
|
conn.updateVersion(packet.getVersion());
|
||||||
conn.updateState(packet.getNextState());
|
conn.updateState(packet.getNextState());
|
||||||
|
|
||||||
Logger.debug("Pinged from %s [%s]", conn.getAddress(),
|
Log.debug("Pinged from %s [%s]", conn.getAddress(),
|
||||||
conn.getClientVersion().toString());
|
conn.getClientVersion().toString());
|
||||||
|
|
||||||
if (server.getConfig().getInfoForwarding().isLegacy()) {
|
if (server.getConfig().getInfoForwarding().isLegacy()) {
|
||||||
|
@ -4,7 +4,7 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import ua.nanit.limbo.server.Logger;
|
import ua.nanit.limbo.server.Log;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ public class ChannelTrafficHandler extends ChannelInboundHandlerAdapter {
|
|||||||
|
|
||||||
private void closeConnection(ChannelHandlerContext ctx, String reason, Object... args) {
|
private void closeConnection(ChannelHandlerContext ctx, String reason, Object... args) {
|
||||||
ctx.close();
|
ctx.close();
|
||||||
Logger.info(reason, args);
|
Log.info(reason, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PacketBucket {
|
private static class PacketBucket {
|
||||||
|
@ -24,7 +24,7 @@ import ua.nanit.limbo.protocol.ByteMessage;
|
|||||||
import ua.nanit.limbo.protocol.Packet;
|
import ua.nanit.limbo.protocol.Packet;
|
||||||
import ua.nanit.limbo.protocol.registry.State;
|
import ua.nanit.limbo.protocol.registry.State;
|
||||||
import ua.nanit.limbo.protocol.registry.Version;
|
import ua.nanit.limbo.protocol.registry.Version;
|
||||||
import ua.nanit.limbo.server.Logger;
|
import ua.nanit.limbo.server.Log;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -47,22 +47,20 @@ public class PacketDecoder extends MessageToMessageDecoder<ByteBuf> {
|
|||||||
Packet packet = mappings.getPacket(packetId);
|
Packet packet = mappings.getPacket(packetId);
|
||||||
|
|
||||||
if (packet != null) {
|
if (packet != null) {
|
||||||
Logger.debug("Received packet %s[0x%s] (%d bytes)", packet.toString(), Integer.toHexString(packetId), msg.readableBytes());
|
Log.debug("Received packet %s[0x%s] (%d bytes)", packet.toString(), Integer.toHexString(packetId), msg.readableBytes());
|
||||||
try {
|
try {
|
||||||
packet.decode(msg, version);
|
packet.decode(msg, version);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (Logger.isDebug()) {
|
if (Log.isDebug()) {
|
||||||
Logger.warning("Cannot decode packet 0x%s", Integer.toHexString(packetId));
|
Log.warning("Cannot decode packet 0x%s", e, Integer.toHexString(packetId));
|
||||||
e.printStackTrace();
|
} else {
|
||||||
}
|
Log.warning("Cannot decode packet 0x%s: %s", Integer.toHexString(packetId), e.getMessage());
|
||||||
else {
|
|
||||||
Logger.warning("Cannot decode packet 0x%s: %s", Integer.toHexString(packetId), e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.fireChannelRead(packet);
|
ctx.fireChannelRead(packet);
|
||||||
} else {
|
} else {
|
||||||
Logger.debug("Undefined incoming packet: 0x" + Integer.toHexString(packetId));
|
Log.debug("Undefined incoming packet: 0x" + Integer.toHexString(packetId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ import ua.nanit.limbo.protocol.Packet;
|
|||||||
import ua.nanit.limbo.protocol.PacketSnapshot;
|
import ua.nanit.limbo.protocol.PacketSnapshot;
|
||||||
import ua.nanit.limbo.protocol.registry.State;
|
import ua.nanit.limbo.protocol.registry.State;
|
||||||
import ua.nanit.limbo.protocol.registry.Version;
|
import ua.nanit.limbo.protocol.registry.Version;
|
||||||
import ua.nanit.limbo.server.Logger;
|
import ua.nanit.limbo.server.Log;
|
||||||
|
|
||||||
public class PacketEncoder extends MessageToByteEncoder<Packet> {
|
public class PacketEncoder extends MessageToByteEncoder<Packet> {
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ public class PacketEncoder extends MessageToByteEncoder<Packet> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (packetId == -1) {
|
if (packetId == -1) {
|
||||||
Logger.warning("Undefined packet class: %s[0x%s] (%d bytes)", packet.getClass().getName(), Integer.toHexString(packetId), msg.readableBytes());
|
Log.warning("Undefined packet class: %s[0x%s] (%d bytes)", packet.getClass().getName(), Integer.toHexString(packetId), msg.readableBytes());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,11 +60,11 @@ public class PacketEncoder extends MessageToByteEncoder<Packet> {
|
|||||||
try {
|
try {
|
||||||
packet.encode(msg, version);
|
packet.encode(msg, version);
|
||||||
|
|
||||||
if (Logger.getLevel() >= Logger.Level.DEBUG.getIndex()) {
|
if (Log.isDebug()) {
|
||||||
Logger.debug("Sending %s[0x%s] packet (%d bytes)", packet.toString(), Integer.toHexString(packetId), msg.readableBytes());
|
Log.debug("Sending %s[0x%s] packet (%d bytes)", packet.toString(), Integer.toHexString(packetId), msg.readableBytes());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.error("Cannot encode packet 0x%s: %s", Integer.toHexString(packetId), e.getMessage());
|
Log.error("Cannot encode packet 0x%s: %s", Integer.toHexString(packetId), e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ package ua.nanit.limbo.connection.pipeline;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
import ua.nanit.limbo.server.Logger;
|
import ua.nanit.limbo.server.Log;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ public class VarIntFrameDecoder extends ByteToMessageDecoder {
|
|||||||
int readVarInt = reader.getReadVarInt();
|
int readVarInt = reader.getReadVarInt();
|
||||||
int bytesRead = reader.getBytesRead();
|
int bytesRead = reader.getBytesRead();
|
||||||
if (readVarInt < 0) {
|
if (readVarInt < 0) {
|
||||||
Logger.error("[VarIntFrameDecoder] Bad data length");
|
Log.error("[VarIntFrameDecoder] Bad data length");
|
||||||
} else if (readVarInt == 0) {
|
} else if (readVarInt == 0) {
|
||||||
in.readerIndex(varIntEnd + 1);
|
in.readerIndex(varIntEnd + 1);
|
||||||
} else {
|
} else {
|
||||||
@ -54,7 +54,7 @@ public class VarIntFrameDecoder extends ByteToMessageDecoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (reader.getResult() == VarIntByteDecoder.DecodeResult.TOO_BIG) {
|
} else if (reader.getResult() == VarIntByteDecoder.DecodeResult.TOO_BIG) {
|
||||||
Logger.error("[VarIntFrameDecoder] Too big data");
|
Log.error("[VarIntFrameDecoder] Too big data");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -40,12 +40,12 @@ public final class CommandManager extends Thread {
|
|||||||
try {
|
try {
|
||||||
handler.execute();
|
handler.execute();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
Logger.error("Cannot execute command:", t);
|
Log.error("Cannot execute command:", t);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.info("Unknown command. Type \"help\" to get commands list");
|
Log.info("Unknown command. Type \"help\" to get commands list");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,12 +43,12 @@ public final class Connections {
|
|||||||
|
|
||||||
public void addConnection(ClientConnection connection) {
|
public void addConnection(ClientConnection connection) {
|
||||||
connections.put(connection.getUuid(), connection);
|
connections.put(connection.getUuid(), connection);
|
||||||
Logger.info("Player %s connected (%s) [%s]", connection.getUsername(),
|
Log.info("Player %s connected (%s) [%s]", connection.getUsername(),
|
||||||
connection.getAddress(), connection.getClientVersion());
|
connection.getAddress(), connection.getClientVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeConnection(ClientConnection connection) {
|
public void removeConnection(ClientConnection connection) {
|
||||||
connections.remove(connection.getUuid());
|
connections.remove(connection.getUuid());
|
||||||
Logger.info("Player %s disconnected", connection.getUsername());
|
Log.info("Player %s disconnected", connection.getUsername());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,13 +72,15 @@ public final class LimboServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
Logger.info("Starting server...");
|
Log.info("Starting server...");
|
||||||
|
|
||||||
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
|
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
|
||||||
|
|
||||||
config = new LimboConfig(Paths.get("./"));
|
config = new LimboConfig(Paths.get("./"));
|
||||||
config.load();
|
config.load();
|
||||||
|
|
||||||
|
Log.setLevel(config.getDebugLevel());
|
||||||
|
|
||||||
packetHandler = new PacketHandler(this);
|
packetHandler = new PacketHandler(this);
|
||||||
dimensionRegistry = new DimensionRegistry(this);
|
dimensionRegistry = new DimensionRegistry(this);
|
||||||
dimensionRegistry.load(config.getDimensionType());
|
dimensionRegistry.load(config.getDimensionType());
|
||||||
@ -92,9 +94,7 @@ public final class LimboServer {
|
|||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(this::stop, "NanoLimbo shutdown thread"));
|
Runtime.getRuntime().addShutdownHook(new Thread(this::stop, "NanoLimbo shutdown thread"));
|
||||||
|
|
||||||
Logger.info("Server started on %s", config.getAddress());
|
Log.info("Server started on %s", config.getAddress());
|
||||||
|
|
||||||
Logger.setLevel(config.getDebugLevel());
|
|
||||||
|
|
||||||
commandManager = new CommandManager();
|
commandManager = new CommandManager();
|
||||||
commandManager.registerAll(this);
|
commandManager.registerAll(this);
|
||||||
@ -110,12 +110,12 @@ public final class LimboServer {
|
|||||||
bossGroup = new EpollEventLoopGroup(config.getBossGroupSize());
|
bossGroup = new EpollEventLoopGroup(config.getBossGroupSize());
|
||||||
workerGroup = new EpollEventLoopGroup(config.getWorkerGroupSize());
|
workerGroup = new EpollEventLoopGroup(config.getWorkerGroupSize());
|
||||||
channelClass = EpollServerSocketChannel.class;
|
channelClass = EpollServerSocketChannel.class;
|
||||||
Logger.debug("Using Epoll transport type");
|
Log.debug("Using Epoll transport type");
|
||||||
} else {
|
} else {
|
||||||
bossGroup = new NioEventLoopGroup(config.getBossGroupSize());
|
bossGroup = new NioEventLoopGroup(config.getBossGroupSize());
|
||||||
workerGroup = new NioEventLoopGroup(config.getWorkerGroupSize());
|
workerGroup = new NioEventLoopGroup(config.getWorkerGroupSize());
|
||||||
channelClass = NioServerSocketChannel.class;
|
channelClass = NioServerSocketChannel.class;
|
||||||
Logger.debug("Using Java NIO transport type");
|
Log.debug("Using Java NIO transport type");
|
||||||
}
|
}
|
||||||
|
|
||||||
new ServerBootstrap()
|
new ServerBootstrap()
|
||||||
@ -132,7 +132,7 @@ public final class LimboServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void stop() {
|
private void stop() {
|
||||||
Logger.info("Stopping server...");
|
Log.info("Stopping server...");
|
||||||
|
|
||||||
if (keepAliveTask != null) {
|
if (keepAliveTask != null) {
|
||||||
keepAliveTask.cancel(true);
|
keepAliveTask.cancel(true);
|
||||||
@ -146,7 +146,7 @@ public final class LimboServer {
|
|||||||
workerGroup.shutdownGracefully();
|
workerGroup.shutdownGracefully();
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.info("Server stopped, Goodbye!");
|
Log.info("Server stopped, Goodbye!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,65 +17,66 @@
|
|||||||
|
|
||||||
package ua.nanit.limbo.server;
|
package ua.nanit.limbo.server;
|
||||||
|
|
||||||
import java.time.LocalTime;
|
import ch.qos.logback.classic.Logger;
|
||||||
import java.time.format.DateTimeFormatter;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public final class Logger {
|
public final class Log {
|
||||||
|
|
||||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("hh:mm:ss");
|
private static final Logger LOGGER = (Logger) LoggerFactory.getLogger("Limbo");
|
||||||
private static int debugLevel = Level.INFO.getIndex();
|
private static int debugLevel = Level.INFO.getIndex();
|
||||||
|
|
||||||
private Logger() {}
|
private Log() {}
|
||||||
|
|
||||||
public static int getLevel() {
|
|
||||||
return debugLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void info(Object msg, Object... args) {
|
public static void info(Object msg, Object... args) {
|
||||||
print(Level.INFO, msg, null, args);
|
LOGGER.info(String.format(msg.toString(), args));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debug(Object msg, Object... args) {
|
public static void debug(Object msg, Object... args) {
|
||||||
print(Level.DEBUG, msg, null, args);
|
LOGGER.debug(String.format(msg.toString(), args));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warning(Object msg, Object... args) {
|
public static void warning(Object msg, Object... args) {
|
||||||
print(Level.WARNING, msg, null, args);
|
LOGGER.warn(String.format(msg.toString(), args));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warning(Object msg, Throwable t, Object... args) {
|
public static void warning(Object msg, Throwable t, Object... args) {
|
||||||
print(Level.WARNING, msg, t, args);
|
LOGGER.warn(String.format(msg.toString(), args), t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void error(Object msg, Object... args) {
|
public static void error(Object msg, Object... args) {
|
||||||
print(Level.ERROR, msg, null, args);
|
LOGGER.error(msg.toString(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void error(Object msg, Throwable t, Object... args) {
|
public static void error(Object msg, Throwable t, Object... args) {
|
||||||
print(Level.ERROR, msg, t, args);
|
LOGGER.error(String.format(msg.toString(), args), t);
|
||||||
}
|
|
||||||
|
|
||||||
public static void print(Level level, Object msg, Throwable t, Object... args) {
|
|
||||||
if (debugLevel >= level.getIndex()) {
|
|
||||||
System.out.printf("%s: %s%n", getPrefix(level), String.format(msg.toString(), args));
|
|
||||||
if (t != null) t.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDebug() {
|
public static boolean isDebug() {
|
||||||
return debugLevel >= Level.DEBUG.getIndex();
|
return debugLevel >= Level.DEBUG.getIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getPrefix(Level level) {
|
|
||||||
return String.format("[%s] [%s]", getTime(), level.getDisplay());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getTime() {
|
|
||||||
return LocalTime.now().format(FORMATTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setLevel(int level) {
|
static void setLevel(int level) {
|
||||||
debugLevel = level;
|
debugLevel = level;
|
||||||
|
Logger logback = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
|
||||||
|
|
||||||
|
if (logback != null) {
|
||||||
|
logback.setLevel(convertLevel(level));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ch.qos.logback.classic.Level convertLevel(int level) {
|
||||||
|
switch (level) {
|
||||||
|
case 0:
|
||||||
|
return ch.qos.logback.classic.Level.ERROR;
|
||||||
|
case 1:
|
||||||
|
return ch.qos.logback.classic.Level.WARN;
|
||||||
|
case 2:
|
||||||
|
return ch.qos.logback.classic.Level.INFO;
|
||||||
|
case 3:
|
||||||
|
return ch.qos.logback.classic.Level.DEBUG;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Undefined log level: " + level);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Level {
|
public enum Level {
|
@ -2,7 +2,7 @@ package ua.nanit.limbo.server.commands;
|
|||||||
|
|
||||||
import ua.nanit.limbo.server.Command;
|
import ua.nanit.limbo.server.Command;
|
||||||
import ua.nanit.limbo.server.LimboServer;
|
import ua.nanit.limbo.server.LimboServer;
|
||||||
import ua.nanit.limbo.server.Logger;
|
import ua.nanit.limbo.server.Log;
|
||||||
|
|
||||||
public class CmdConn implements Command {
|
public class CmdConn implements Command {
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ public class CmdConn implements Command {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
Logger.info("Connections: %d", server.getConnections().getCount());
|
Log.info("Connections: %d", server.getConnections().getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,7 +2,7 @@ package ua.nanit.limbo.server.commands;
|
|||||||
|
|
||||||
import ua.nanit.limbo.server.Command;
|
import ua.nanit.limbo.server.Command;
|
||||||
import ua.nanit.limbo.server.LimboServer;
|
import ua.nanit.limbo.server.LimboServer;
|
||||||
import ua.nanit.limbo.server.Logger;
|
import ua.nanit.limbo.server.Log;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -18,10 +18,10 @@ public class CmdHelp implements Command {
|
|||||||
public void execute() {
|
public void execute() {
|
||||||
Map<String, Command> commands = server.getCommandManager().getCommands();
|
Map<String, Command> commands = server.getCommandManager().getCommands();
|
||||||
|
|
||||||
Logger.info("Available commands:");
|
Log.info("Available commands:");
|
||||||
|
|
||||||
for (Map.Entry<String, Command> entry : commands.entrySet()) {
|
for (Map.Entry<String, Command> entry : commands.entrySet()) {
|
||||||
Logger.info("%s - %s", entry.getKey(), entry.getValue().description());
|
Log.info("%s - %s", entry.getKey(), entry.getValue().description());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package ua.nanit.limbo.server.commands;
|
package ua.nanit.limbo.server.commands;
|
||||||
|
|
||||||
import ua.nanit.limbo.server.Command;
|
import ua.nanit.limbo.server.Command;
|
||||||
import ua.nanit.limbo.server.Logger;
|
import ua.nanit.limbo.server.Log;
|
||||||
|
|
||||||
public class CmdMem implements Command {
|
public class CmdMem implements Command {
|
||||||
|
|
||||||
@ -14,11 +14,11 @@ public class CmdMem implements Command {
|
|||||||
long free = runtime.freeMemory() / mb;
|
long free = runtime.freeMemory() / mb;
|
||||||
long max = runtime.maxMemory() / mb;
|
long max = runtime.maxMemory() / mb;
|
||||||
|
|
||||||
Logger.info("Memory usage:");
|
Log.info("Memory usage:");
|
||||||
Logger.info("Used: %d MB", used);
|
Log.info("Used: %d MB", used);
|
||||||
Logger.info("Total: %d MB", total);
|
Log.info("Total: %d MB", total);
|
||||||
Logger.info("Free: %d MB", free);
|
Log.info("Free: %d MB", free);
|
||||||
Logger.info("Max: %d MB", max);
|
Log.info("Max: %d MB", max);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package ua.nanit.limbo.server.commands;
|
package ua.nanit.limbo.server.commands;
|
||||||
|
|
||||||
import ua.nanit.limbo.server.Command;
|
import ua.nanit.limbo.server.Command;
|
||||||
import ua.nanit.limbo.server.Logger;
|
import ua.nanit.limbo.server.Log;
|
||||||
import ua.nanit.limbo.BuildConfig;
|
import ua.nanit.limbo.BuildConfig;
|
||||||
|
|
||||||
public class CmdVersion implements Command {
|
public class CmdVersion implements Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
Logger.info("Version: %s", BuildConfig.LIMBO_VERSION);
|
Log.info("Version: %s", BuildConfig.LIMBO_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,7 +21,7 @@ import net.kyori.adventure.nbt.CompoundBinaryTag;
|
|||||||
import net.kyori.adventure.nbt.ListBinaryTag;
|
import net.kyori.adventure.nbt.ListBinaryTag;
|
||||||
import net.kyori.adventure.nbt.TagStringIO;
|
import net.kyori.adventure.nbt.TagStringIO;
|
||||||
import ua.nanit.limbo.server.LimboServer;
|
import ua.nanit.limbo.server.LimboServer;
|
||||||
import ua.nanit.limbo.server.Logger;
|
import ua.nanit.limbo.server.Log;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -118,7 +118,7 @@ public final class DimensionRegistry {
|
|||||||
case "the_end":
|
case "the_end":
|
||||||
return new Dimension(1, "minecraft:the_end", theEnd);
|
return new Dimension(1, "minecraft:the_end", theEnd);
|
||||||
default:
|
default:
|
||||||
Logger.warning("Undefined dimension type: '%s'. Using THE_END as default", def);
|
Log.warning("Undefined dimension type: '%s'. Using THE_END as default", def);
|
||||||
return new Dimension(1, "minecraft:the_end", theEnd);
|
return new Dimension(1, "minecraft:the_end", theEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ public final class DimensionRegistry {
|
|||||||
case "the_end":
|
case "the_end":
|
||||||
return new Dimension(3, "minecraft:the_end", tag);
|
return new Dimension(3, "minecraft:the_end", tag);
|
||||||
default:
|
default:
|
||||||
Logger.warning("Undefined dimension type: '%s'. Using THE_END as default", def);
|
Log.warning("Undefined dimension type: '%s'. Using THE_END as default", def);
|
||||||
return new Dimension(3, "minecraft:the_end", tag);
|
return new Dimension(3, "minecraft:the_end", tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
30
src/main/resources/logback.xml
Normal file
30
src/main/resources/logback.xml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE configuration>
|
||||||
|
|
||||||
|
<configuration>
|
||||||
|
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
|
||||||
|
<import class="ch.qos.logback.core.ConsoleAppender"/>
|
||||||
|
<import class="ch.qos.logback.core.FileAppender"/>
|
||||||
|
|
||||||
|
<timestamp key="bySecond" datePattern="yyyy-MM-dd"/>
|
||||||
|
|
||||||
|
<appender name="STDOUT" class="ConsoleAppender">
|
||||||
|
<encoder class="PatternLayoutEncoder">
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} -%kvp- %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="FILE" class="FileAppender">
|
||||||
|
<file>logs/log-${bySecond}.txt</file>
|
||||||
|
<immediateFlush>true</immediateFlush>
|
||||||
|
|
||||||
|
<encoder class="PatternLayoutEncoder">
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} -%kvp- %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="FILE"/>
|
||||||
|
<appender-ref ref="STDOUT"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
Loading…
x
Reference in New Issue
Block a user