mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-10 18:57:39 +07:00
Added log file
This commit is contained in:
parent
d6dec002c1
commit
dbc45985ce
@ -11,7 +11,7 @@ import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import arc.util.async.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.ctype.Content;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
@ -33,6 +33,7 @@ public abstract class ClientLauncher extends ApplicationCore implements Platform
|
||||
@Override
|
||||
public void setup(){
|
||||
Vars.loadLogger();
|
||||
Vars.loadFileLogger();
|
||||
Vars.platform = this;
|
||||
beginTime = Time.millis();
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
package mindustry;
|
||||
|
||||
import arc.*;
|
||||
import arc.Application.*;
|
||||
import arc.*;
|
||||
import arc.assets.*;
|
||||
import arc.struct.*;
|
||||
import arc.files.*;
|
||||
import arc.graphics.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.Log.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.ai.*;
|
||||
import mindustry.core.*;
|
||||
@ -21,10 +22,11 @@ import mindustry.gen.*;
|
||||
import mindustry.input.*;
|
||||
import mindustry.maps.*;
|
||||
import mindustry.mod.*;
|
||||
import mindustry.net.*;
|
||||
import mindustry.net.Net;
|
||||
import mindustry.net.*;
|
||||
import mindustry.world.blocks.defense.ForceProjector.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.*;
|
||||
import java.util.*;
|
||||
|
||||
@ -35,7 +37,7 @@ public class Vars implements Loadable{
|
||||
/** Whether to load locales.*/
|
||||
public static boolean loadLocales = true;
|
||||
/** Whether the logger is loaded. */
|
||||
public static boolean loadedLogger = false;
|
||||
public static boolean loadedLogger = false, loadedFileLogger = false;
|
||||
/** Maximum schematic size.*/
|
||||
public static final int maxSchematicSize = 32;
|
||||
/** All schematic base64 starts with this string.*/
|
||||
@ -282,9 +284,10 @@ public class Vars implements Loadable{
|
||||
String[] stags = {"&lc&fb[D]", "&lg&fb[I]", "&ly&fb[W]", "&lr&fb[E]", ""};
|
||||
|
||||
Array<String> logBuffer = new Array<>();
|
||||
Log.setLogger((level, text, args) -> {
|
||||
String result = Log.format(text, args);
|
||||
System.out.println(Log.format(stags[level.ordinal()] + "&fr " + text, args));
|
||||
Log.setLogger((level, text) -> {
|
||||
String result = text;
|
||||
String rawText = Log.format(stags[level.ordinal()] + "&fr " + text);
|
||||
System.out.println(rawText);
|
||||
|
||||
result = tags[level.ordinal()] + " " + result;
|
||||
|
||||
@ -300,6 +303,28 @@ public class Vars implements Loadable{
|
||||
loadedLogger = true;
|
||||
}
|
||||
|
||||
public static void loadFileLogger(){
|
||||
if(loadedFileLogger) return;
|
||||
|
||||
Core.settings.setAppName(appName);
|
||||
|
||||
Writer writer = settings.getDataDirectory().child("last_log.txt").writer(false);
|
||||
LogHandler log = Log.getLogger();
|
||||
Log.setLogger(((level, text) -> {
|
||||
log.log(level, text);
|
||||
|
||||
try{
|
||||
writer.write("[" + Character.toUpperCase(level.name().charAt(0)) +"] " + Log.removeCodes(text) + "\n");
|
||||
writer.flush();
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
//ignore it
|
||||
}
|
||||
}));
|
||||
|
||||
loadedFileLogger = true;
|
||||
}
|
||||
|
||||
public static void loadSettings(){
|
||||
Core.settings.setAppName(appName);
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=a4d492223bec8586254a009f4805642e0e5e018f
|
||||
archash=145648d83c4659f727ea8b6676006747b87e7716
|
||||
|
@ -66,17 +66,17 @@ public class ServerControl implements ApplicationListener{
|
||||
"globalrules", "{reactorExplosions: false}"
|
||||
);
|
||||
|
||||
Log.setLogger((level, text, args1) -> {
|
||||
String result = "[" + dateTime.format(LocalDateTime.now()) + "] " + format(tags[level.ordinal()] + " " + text + "&fr", args1);
|
||||
Log.setLogger((level, text) -> {
|
||||
String result = "[" + dateTime.format(LocalDateTime.now()) + "] " + format(tags[level.ordinal()] + " " + text + "&fr");
|
||||
System.out.println(result);
|
||||
|
||||
if(Config.logging.bool()){
|
||||
logToFile("[" + dateTime.format(LocalDateTime.now()) + "] " + format(tags[level.ordinal()] + " " + text + "&fr", false, args1));
|
||||
logToFile("[" + dateTime.format(LocalDateTime.now()) + "] " + formatColors(tags[level.ordinal()] + " " + text + "&fr", false));
|
||||
}
|
||||
|
||||
if(socketOutput != null){
|
||||
try{
|
||||
socketOutput.println(format(text + "&fr", false, args1));
|
||||
socketOutput.println(formatColors(text + "&fr", false));
|
||||
}catch(Throwable e){
|
||||
err("Error occurred logging to socket: {0}", e.getClass().getSimpleName());
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ public class ServerLauncher implements ApplicationListener{
|
||||
Vars.platform = new Platform(){};
|
||||
Vars.net = new Net(platform.getNet());
|
||||
|
||||
Log.setLogger((level, text, args1) -> {
|
||||
String result = "[" + dateTime.format(LocalDateTime.now()) + "] " + format(tags[level.ordinal()] + " " + text + "&fr", args1);
|
||||
Log.setLogger((level, text) -> {
|
||||
String result = "[" + dateTime.format(LocalDateTime.now()) + "] " + format(tags[level.ordinal()] + " " + text + "&fr");
|
||||
System.out.println(result);
|
||||
});
|
||||
new HeadlessApplication(new ServerLauncher(), null, throwable -> CrashSender.send(throwable, f -> {}));
|
||||
|
Loading…
Reference in New Issue
Block a user