mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 17:37:58 -04:00
log handling now in own thread
This commit is contained in:
parent
faae40e0dc
commit
eb05a86704
@ -16,6 +16,9 @@ public class Minosoft {
|
||||
static Configuration config;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// int log thread
|
||||
Log.initThread();
|
||||
|
||||
Log.info("Starting...");
|
||||
setConfigFolder();
|
||||
Log.info("Reading config file...");
|
||||
@ -39,20 +42,25 @@ public class Minosoft {
|
||||
* Sets Config.homeDir to the correct folder per OS
|
||||
*/
|
||||
public static void setConfigFolder() {
|
||||
String folder = System.getProperty("user.home");
|
||||
if (!folder.endsWith(File.separator)) {
|
||||
folder += "/";
|
||||
String path = System.getProperty("user.home");
|
||||
if (!path.endsWith(File.separator)) {
|
||||
path += "/";
|
||||
}
|
||||
switch (OSUtil.getOS()) {
|
||||
case LINUX:
|
||||
folder += ".local/share/minosoft/";
|
||||
path += ".local/share/minosoft/";
|
||||
break;
|
||||
case WINDOWS:
|
||||
Config.homeDir = "AppData/Roaming/Minosoft/";
|
||||
path = "AppData/Roaming/Minosoft/";
|
||||
break;
|
||||
//ToDo: Mac, Other
|
||||
}
|
||||
Config.homeDir = folder;
|
||||
File folder = new File(path);
|
||||
if (!folder.exists() && !folder.mkdirs()) {
|
||||
// failed creating folder
|
||||
throw new RuntimeException(String.format("Could not create home folder (%s)!", path));
|
||||
}
|
||||
Config.homeDir = path;
|
||||
}
|
||||
|
||||
public static Configuration getConfig() {
|
||||
|
@ -28,7 +28,6 @@ public class World {
|
||||
}
|
||||
|
||||
public Block getBlock(BlockPosition pos) {
|
||||
//ToDo
|
||||
ChunkLocation loc = pos.getChunkLocation();
|
||||
if (getChunk(loc) != null) {
|
||||
return getChunk(loc).getBlock(pos.getX() % 16, pos.getX(), pos.getZ() % 16);
|
||||
|
@ -1,17 +1,41 @@
|
||||
package de.bixilon.minosoft.logging;
|
||||
|
||||
import de.bixilon.minosoft.util.Util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Log {
|
||||
static LogLevel level = LogLevel.PROTOCOL;
|
||||
final static SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
final static List<String> queue = new ArrayList<>();
|
||||
|
||||
public static void log(LogLevel l, String message) {
|
||||
if (l.getId() > level.getId()) {
|
||||
// log level too low
|
||||
return;
|
||||
}
|
||||
System.out.println(String.format("[%s] [%s] %s", timeFormat.format(System.currentTimeMillis()), l.name(), message));
|
||||
queue.add(String.format("[%s] [%s] %s", timeFormat.format(System.currentTimeMillis()), l.name(), message));
|
||||
}
|
||||
|
||||
public static void initThread() {
|
||||
|
||||
Thread logThread = new Thread(() -> {
|
||||
while (true) {
|
||||
while (queue.size() > 0) {
|
||||
// something to print
|
||||
System.out.println(queue.get(0));
|
||||
|
||||
//ToDo: log to file
|
||||
|
||||
queue.remove(0);
|
||||
}
|
||||
Util.sleep(1);
|
||||
}
|
||||
|
||||
});
|
||||
logThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user