mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-21 20:22:45 +02:00
[New] Set DebugLogger in ConfigSystem
Old Abstract Plugin Framework functionality did this differently, but now this falls on the hands of developers to not limit the settings.
This commit is contained in:
parent
c4bf9a500f
commit
6bb24c3903
|
@ -9,12 +9,16 @@ import com.djrapitops.plan.system.SubSystem;
|
|||
import com.djrapitops.plan.system.file.PlanFiles;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.debug.*;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* System for Config and other user customizable options.
|
||||
|
@ -27,17 +31,20 @@ public abstract class ConfigSystem implements SubSystem {
|
|||
protected final PlanFiles files;
|
||||
protected final PlanConfig config;
|
||||
protected final Theme theme;
|
||||
private final PluginLogger logger;
|
||||
protected final ErrorHandler errorHandler;
|
||||
|
||||
public ConfigSystem(
|
||||
PlanFiles files,
|
||||
PlanConfig config,
|
||||
Theme theme,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.files = files;
|
||||
this.config = config;
|
||||
this.theme = theme;
|
||||
this.logger = logger;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
|
@ -55,14 +62,30 @@ public abstract class ConfigSystem implements SubSystem {
|
|||
copyDefaults();
|
||||
config.save();
|
||||
|
||||
// TODO Set Debug logger somewhere
|
||||
Log.setDebugMode(config.getString(Settings.DEBUG));
|
||||
setDebugMode();
|
||||
} catch (IOException e) {
|
||||
throw new EnableException("Failed to save default config.", e);
|
||||
}
|
||||
theme.enable();
|
||||
}
|
||||
|
||||
private void setDebugMode() {
|
||||
String debugMode = config.getString(Settings.DEBUG);
|
||||
|
||||
List<DebugLogger> loggers = new ArrayList<>();
|
||||
if (Verify.equalsOne(debugMode, "true", "both", "console")) {
|
||||
loggers.add(new ConsoleDebugLogger(logger));
|
||||
}
|
||||
if (Verify.equalsOne(debugMode, "true", "both", "file")) {
|
||||
loggers.add(new FolderTimeStampFileDebugLogger(files.getLogsFolder(), () -> errorHandler));
|
||||
}
|
||||
if (logger.getDebugLogger() instanceof CombineDebugLogger) {
|
||||
CombineDebugLogger debugLogger = (CombineDebugLogger) logger.getDebugLogger();
|
||||
loggers.add(debugLogger.getDebugLogger(MemoryDebugLogger.class).orElse(new MemoryDebugLogger()));
|
||||
debugLogger.setDebugLoggers(loggers.toArray(new DebugLogger[0]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies default values from file in jar to Config.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user