mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-20 09:17:29 +07:00
Committing logger console commands and Riiablo.logs within Client
This commit is contained in:
parent
962938bcb3
commit
7d908b1e6c
@ -59,6 +59,7 @@ import com.riiablo.loader.DC6Loader;
|
||||
import com.riiablo.loader.DCCLoader;
|
||||
import com.riiablo.loader.IndexLoader;
|
||||
import com.riiablo.loader.PaletteLoader;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.map.DS1;
|
||||
import com.riiablo.map.DS1Loader;
|
||||
import com.riiablo.map.DT1;
|
||||
@ -112,6 +113,7 @@ public class Client extends Game {
|
||||
private CharData charData;
|
||||
private D2 anim;
|
||||
private Metrics metrics;
|
||||
private LogManager logs;
|
||||
|
||||
private boolean forceWindowed;
|
||||
private boolean forceDrawFps;
|
||||
@ -214,6 +216,7 @@ public class Client extends Game {
|
||||
@Override
|
||||
public void create() {
|
||||
Riiablo.client = this;
|
||||
Riiablo.logs = logs = LogManager.INSTANCE;
|
||||
Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||
|
||||
// This is needed so that home is in a platform-dependent handle
|
||||
@ -493,6 +496,7 @@ public class Client extends Game {
|
||||
@Override
|
||||
public void resume() {
|
||||
Riiablo.client = this;
|
||||
Riiablo.logs = logs;
|
||||
Riiablo.home = home;
|
||||
Riiablo.viewport = viewport;
|
||||
Riiablo.defaultViewport = defaultViewport;
|
||||
|
@ -5,6 +5,10 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.apache.logging.log4j.spi.LoggerContext;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
@ -273,4 +277,44 @@ public class Commands {
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
public static final Command getlogger = Command.builder()
|
||||
.alias("getlogger")
|
||||
.description("Prints the log level for the specified logger")
|
||||
.params(Parameter.of(String.class).suggester(LoggerSuggester.INSTANCE))
|
||||
.action(new Action() {
|
||||
@Override
|
||||
public void onExecuted(Command.Instance instance) {
|
||||
String name = instance.getArg(0);
|
||||
LoggerContext context = LogManager.getContext(false);
|
||||
Level level;
|
||||
if (name.equalsIgnoreCase("root")) {
|
||||
level = context.getLogger(LogManager.ROOT_LOGGER_NAME).getLevel();
|
||||
} else {
|
||||
level = context.getLogger(name).getLevel();
|
||||
}
|
||||
Riiablo.console.out.println(level);
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
public static final Command setlogger = Command.builder()
|
||||
.alias("setlogger")
|
||||
.description("Sets the log level for the specified logger")
|
||||
.params(
|
||||
Parameter.of(String.class).suggester(LoggerSuggester.INSTANCE),
|
||||
Parameter.of(String.class).suggester(LoggerLevelSuggester.INSTANCE))
|
||||
.action(new Action() {
|
||||
@Override
|
||||
public void onExecuted(Command.Instance instance) {
|
||||
String name = instance.getArg(0);
|
||||
Level level = Level.toLevel(instance.getArg(1), null);
|
||||
if (level == null) {
|
||||
Riiablo.console.out.println("Unknown log level: " + instance.getArg(1));
|
||||
return;
|
||||
}
|
||||
Configurator.setLevel(name, level);
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
47
core/src/com/riiablo/LoggerLevelSuggester.java
Normal file
47
core/src/com/riiablo/LoggerLevelSuggester.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.riiablo;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import org.apache.commons.collections4.Trie;
|
||||
import org.apache.commons.collections4.trie.PatriciaTrie;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import com.riiablo.console.Console;
|
||||
import com.riiablo.console.ConsoleUtils;
|
||||
import com.riiablo.util.StringUtils;
|
||||
|
||||
public enum LoggerLevelSuggester implements Console.SuggestionProvider {
|
||||
INSTANCE;
|
||||
|
||||
private static final Trie<String, Level> LEVELS = new PatriciaTrie<>();
|
||||
static {
|
||||
for (Level level : Level.values()) {
|
||||
LEVELS.put(level.name().toLowerCase(), level);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int suggest(Console console, CharSequence buffer, String[] args, int targetArg) {
|
||||
String arg = targetArg == args.length ? "" : args[targetArg];
|
||||
SortedMap<String, ?> keys = LEVELS.prefixMap(arg);
|
||||
switch (keys.size()) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
String alias = keys.firstKey();
|
||||
console.in.append(alias, arg.length());
|
||||
break;
|
||||
default:
|
||||
Set<String> aliases = keys.keySet();
|
||||
String commonPrefix = StringUtils.commonPrefix(aliases);
|
||||
if (commonPrefix.length() > arg.length()) {
|
||||
console.in.append(commonPrefix, arg.length());
|
||||
} else {
|
||||
ConsoleUtils.printList(console, aliases, 0, 0);
|
||||
}
|
||||
|
||||
return aliases.size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
37
core/src/com/riiablo/LoggerSuggester.java
Normal file
37
core/src/com/riiablo/LoggerSuggester.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.riiablo;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
|
||||
import com.riiablo.console.Console;
|
||||
import com.riiablo.console.ConsoleUtils;
|
||||
import com.riiablo.util.StringUtils;
|
||||
|
||||
public enum LoggerSuggester implements Console.SuggestionProvider {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public int suggest(Console console, CharSequence buffer, String[] args, int targetArg) {
|
||||
String arg = targetArg == args.length ? "" : args[targetArg];
|
||||
SortedMap<String, ?> keys = Riiablo.logs.prefixMap(arg);
|
||||
switch (keys.size()) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
String alias = keys.firstKey();
|
||||
console.in.append(alias, arg.length());
|
||||
break;
|
||||
default:
|
||||
Set<String> aliases = keys.keySet();
|
||||
String commonPrefix = StringUtils.commonPrefix(aliases);
|
||||
if (commonPrefix.length() > arg.length()) {
|
||||
console.in.append(commonPrefix, arg.length());
|
||||
} else {
|
||||
ConsoleUtils.printList(console, aliases, 0, 0);
|
||||
}
|
||||
|
||||
return aliases.size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user