mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Введение нового уровня логгирования: dev
This commit is contained in:
parent
9b7dec7360
commit
aceb06bc9d
5 changed files with 58 additions and 22 deletions
|
@ -367,6 +367,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
||||||
config = Launcher.gson.fromJson(reader, Config.class);
|
config = Launcher.gson.fromJson(reader, Config.class);
|
||||||
}
|
}
|
||||||
config.verify();
|
config.verify();
|
||||||
|
Launcher.applyLauncherEnv(config.env);
|
||||||
for (AuthProvider provider : config.authProvider) {
|
for (AuthProvider provider : config.authProvider) {
|
||||||
provider.init();
|
provider.init();
|
||||||
}
|
}
|
||||||
|
@ -396,13 +397,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
||||||
if (config.textureProvider instanceof Reloadable)
|
if (config.textureProvider instanceof Reloadable)
|
||||||
reloadManager.registerReloadable("textureProvider", (Reloadable) config.textureProvider);
|
reloadManager.registerReloadable("textureProvider", (Reloadable) config.textureProvider);
|
||||||
|
|
||||||
Arrays.stream(config.mirrors).forEach(s -> {
|
Arrays.stream(config.mirrors).forEach(mirrorManager::addMirror);
|
||||||
try {
|
|
||||||
mirrorManager.addMirror(s);
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (config.permissionsHandler instanceof Reconfigurable)
|
if (config.permissionsHandler instanceof Reconfigurable)
|
||||||
reconfigurableManager.registerReconfigurable("permissionsHandler", (Reconfigurable) config.permissionsHandler);
|
reconfigurableManager.registerReconfigurable("permissionsHandler", (Reconfigurable) config.permissionsHandler);
|
||||||
|
@ -416,13 +411,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
||||||
if (config.textureProvider instanceof Reconfigurable)
|
if (config.textureProvider instanceof Reconfigurable)
|
||||||
reconfigurableManager.registerReconfigurable("textureProvider", (Reconfigurable) config.textureProvider);
|
reconfigurableManager.registerReconfigurable("textureProvider", (Reconfigurable) config.textureProvider);
|
||||||
|
|
||||||
Arrays.stream(config.mirrors).forEach(s -> {
|
Arrays.stream(config.mirrors).forEach(mirrorManager::addMirror);
|
||||||
try {
|
|
||||||
mirrorManager.addMirror(s);
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// init modules
|
// init modules
|
||||||
modulesManager.initModules();
|
modulesManager.initModules();
|
||||||
|
|
|
@ -108,6 +108,8 @@ public static void main(String... args) throws Throwable {
|
||||||
}
|
}
|
||||||
LauncherConfig cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname);
|
LauncherConfig cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname);
|
||||||
Launcher.setConfig(cfg);
|
Launcher.setConfig(cfg);
|
||||||
|
if(config.env != null) Launcher.applyLauncherEnv(config.env);
|
||||||
|
else Launcher.applyLauncherEnv(LauncherConfig.LauncherEnvironment.STD);
|
||||||
if (config.logFile != null) LogHelper.addOutput(IOHelper.newWriter(Paths.get(config.logFile), true));
|
if (config.logFile != null) LogHelper.addOutput(IOHelper.newWriter(Paths.get(config.logFile), true));
|
||||||
if (config.syncAuth) auth(wrapper);
|
if (config.syncAuth) auth(wrapper);
|
||||||
else
|
else
|
||||||
|
@ -176,6 +178,7 @@ private static void generateConfigIfNotExists() throws IOException {
|
||||||
newConfig.stopOnError = true;
|
newConfig.stopOnError = true;
|
||||||
newConfig.reconnectCount = 10;
|
newConfig.reconnectCount = 10;
|
||||||
newConfig.reconnectSleep = 1000;
|
newConfig.reconnectSleep = 1000;
|
||||||
|
newConfig.env = LauncherConfig.LauncherEnvironment.STD;
|
||||||
//try(Reader reader = IOHelper.newReader(IOHelper.getResourceURL("ru/gravit/launcher/server/ServerWrapper.cfg")))
|
//try(Reader reader = IOHelper.newReader(IOHelper.getResourceURL("ru/gravit/launcher/server/ServerWrapper.cfg")))
|
||||||
//{
|
//{
|
||||||
// newConfig = gson.fromJson(reader,Config.class);
|
// newConfig = gson.fromJson(reader,Config.class);
|
||||||
|
@ -207,6 +210,7 @@ public static final class Config {
|
||||||
public String mainclass;
|
public String mainclass;
|
||||||
public String login;
|
public String login;
|
||||||
public String password;
|
public String password;
|
||||||
|
public LauncherConfig.LauncherEnvironment env;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientProfile profile;
|
public ClientProfile profile;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import ru.gravit.utils.Version;
|
import ru.gravit.utils.Version;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.JVMHelper;
|
import ru.gravit.utils.helper.JVMHelper;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -130,4 +131,27 @@ public static Version getVersion() {
|
||||||
public static boolean isUsingAvanguard() {
|
public static boolean isUsingAvanguard() {
|
||||||
return JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE && useAvanguard;
|
return JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE && useAvanguard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void applyLauncherEnv(LauncherConfig.LauncherEnvironment env)
|
||||||
|
{
|
||||||
|
switch (env)
|
||||||
|
{
|
||||||
|
case DEV:
|
||||||
|
LogHelper.setDevEnabled(true);
|
||||||
|
LogHelper.setStacktraceEnabled(true);
|
||||||
|
LogHelper.setDebugEnabled(true);
|
||||||
|
break;
|
||||||
|
case DEBUG:
|
||||||
|
LogHelper.setDebugEnabled(true);
|
||||||
|
LogHelper.setStacktraceEnabled(true);
|
||||||
|
break;
|
||||||
|
case STD:
|
||||||
|
break;
|
||||||
|
case PROD:
|
||||||
|
LogHelper.setStacktraceEnabled(false);
|
||||||
|
LogHelper.setDebugEnabled(false);
|
||||||
|
LogHelper.setDevEnabled(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,13 +60,7 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException
|
||||||
else if (config.env == 2) env = LauncherEnvironment.STD;
|
else if (config.env == 2) env = LauncherEnvironment.STD;
|
||||||
else if (config.env == 3) env = LauncherEnvironment.PROD;
|
else if (config.env == 3) env = LauncherEnvironment.PROD;
|
||||||
else env = LauncherEnvironment.STD;
|
else env = LauncherEnvironment.STD;
|
||||||
if (env == LauncherEnvironment.PROD) {
|
Launcher.applyLauncherEnv(env);
|
||||||
LogHelper.setStacktraceEnabled(false);
|
|
||||||
LogHelper.setDebugEnabled(false);
|
|
||||||
}
|
|
||||||
if (env == LauncherEnvironment.DEV || env == LauncherEnvironment.DEBUG) {
|
|
||||||
LogHelper.setDebugEnabled(true);
|
|
||||||
}
|
|
||||||
// Read signed runtime
|
// Read signed runtime
|
||||||
int count = input.readLength(0);
|
int count = input.readLength(0);
|
||||||
Map<String, byte[]> localResources = new HashMap<>(count);
|
Map<String, byte[]> localResources = new HashMap<>(count);
|
||||||
|
|
|
@ -22,6 +22,8 @@ public final class LogHelper {
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static final String DEBUG_PROPERTY = "launcher.debug";
|
public static final String DEBUG_PROPERTY = "launcher.debug";
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
public static final String DEV_PROPERTY = "launcher.dev";
|
||||||
|
@LauncherAPI
|
||||||
public static final String STACKTRACE_PROPERTY = "launcher.stacktrace";
|
public static final String STACKTRACE_PROPERTY = "launcher.stacktrace";
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static final String NO_JANSI_PROPERTY = "launcher.noJAnsi";
|
public static final String NO_JANSI_PROPERTY = "launcher.noJAnsi";
|
||||||
|
@ -32,6 +34,7 @@ public final class LogHelper {
|
||||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss", Locale.US);
|
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss", Locale.US);
|
||||||
private static final AtomicBoolean DEBUG_ENABLED = new AtomicBoolean(Boolean.getBoolean(DEBUG_PROPERTY));
|
private static final AtomicBoolean DEBUG_ENABLED = new AtomicBoolean(Boolean.getBoolean(DEBUG_PROPERTY));
|
||||||
private static final AtomicBoolean STACKTRACE_ENABLED = new AtomicBoolean(Boolean.getBoolean(STACKTRACE_PROPERTY));
|
private static final AtomicBoolean STACKTRACE_ENABLED = new AtomicBoolean(Boolean.getBoolean(STACKTRACE_PROPERTY));
|
||||||
|
private static final AtomicBoolean DEV_ENABLED = new AtomicBoolean(Boolean.getBoolean(DEV_PROPERTY));
|
||||||
private static final Set<Output> OUTPUTS = Collections.newSetFromMap(new ConcurrentHashMap<>(2));
|
private static final Set<Output> OUTPUTS = Collections.newSetFromMap(new ConcurrentHashMap<>(2));
|
||||||
private static final Output STD_OUTPUT;
|
private static final Output STD_OUTPUT;
|
||||||
|
|
||||||
|
@ -64,11 +67,23 @@ public static void debug(String message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@LauncherAPI
|
||||||
|
public static void dev(String message) {
|
||||||
|
if (isDevEnabled()) {
|
||||||
|
log(Level.DEV, message, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static void debug(String format, Object... args) {
|
public static void debug(String format, Object... args) {
|
||||||
debug(String.format(format, args));
|
debug(String.format(format, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@LauncherAPI
|
||||||
|
public static void dev(String format, Object... args) {
|
||||||
|
debug(String.format(format, args));
|
||||||
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static void error(Throwable exc) {
|
public static void error(Throwable exc) {
|
||||||
error(isStacktraceEnabled() ? toString(exc) : exc.toString());
|
error(isStacktraceEnabled() ? toString(exc) : exc.toString());
|
||||||
|
@ -109,11 +124,21 @@ public static boolean isStacktraceEnabled() {
|
||||||
return STACKTRACE_ENABLED.get();
|
return STACKTRACE_ENABLED.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@LauncherAPI
|
||||||
|
public static boolean isDevEnabled() {
|
||||||
|
return DEV_ENABLED.get();
|
||||||
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static void setStacktraceEnabled(boolean stacktraceEnabled) {
|
public static void setStacktraceEnabled(boolean stacktraceEnabled) {
|
||||||
STACKTRACE_ENABLED.set(stacktraceEnabled);
|
STACKTRACE_ENABLED.set(stacktraceEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@LauncherAPI
|
||||||
|
public static void setDevEnabled(boolean stacktraceEnabled) {
|
||||||
|
DEV_ENABLED.set(stacktraceEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static void log(Level level, String message, boolean sub) {
|
public static void log(Level level, String message, boolean sub) {
|
||||||
String dateTime = DATE_TIME_FORMATTER.format(LocalDateTime.now());
|
String dateTime = DATE_TIME_FORMATTER.format(LocalDateTime.now());
|
||||||
|
@ -318,7 +343,7 @@ public interface Output {
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public enum Level {
|
public enum Level {
|
||||||
DEBUG("DEBUG"), INFO("INFO"), WARNING("WARN"), ERROR("ERROR");
|
DEV("DEV"),DEBUG("DEBUG"), INFO("INFO"), WARNING("WARN"), ERROR("ERROR");
|
||||||
public final String name;
|
public final String name;
|
||||||
|
|
||||||
Level(String name) {
|
Level(String name) {
|
||||||
|
|
Loading…
Reference in a new issue