Skip to content

Commit

Permalink
Add static logger access
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Dec 11, 2021
1 parent 0fa2099 commit d42418c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
11 changes: 6 additions & 5 deletions GalaxiAPI/global/src/net/ME1312/Galaxi/Library/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ public static <T> T nullpo(T value) {
*
* @param values Values to check
* @throws NullPointerException if any are null
* @return Values
*/
public static void nullpo(Object... values) {
@SafeVarargs
public static <T> T[] nullpo(T... values) {
if (values == null) throw new NullPointerException("Illegal null array");
for (int i = 0; i < values.length; ++i) {
if (values[i] == null) throw new NullPointerException("Illegal null value at position: [" + i + "]");
}
return values;
}

/**
Expand All @@ -57,10 +60,8 @@ public static boolean isNull(Object value) {
*/
public static boolean isNull(Object... values) {
if (values == null) return true;
for (Object value : values) {
if (value == null) {
return true;
}
for (int i = 0; i < values.length; ++i) {
if (values[i] == null) return true;
}
return false;
}
Expand Down
17 changes: 14 additions & 3 deletions GalaxiAPI/src/net/ME1312/Galaxi/Log/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.PrimitiveIterator;
import java.util.concurrent.ExecutorService;
Expand All @@ -19,19 +20,29 @@ public final class Logger {
private static ExecutorService service = null;
static LogStream.MessageHandler writer = null;

private static final HashMap<String, Logger> loggers = new HashMap<String, Logger>();
private static final LinkedList<LogFilter> gFilters = new LinkedList<LogFilter>();
private final LinkedList<LogFilter> lFilters = new LinkedList<LogFilter>();
private final java.util.logging.Logger primitive;
final String prefix;

/**
* Gets a new Logger
* Get a static logger
*
* @param prefix Log Prefix
* @return Logger
*/
public static Logger get(String prefix) {
return loggers.computeIfAbsent(prefix, Logger::new);
}

/**
* Creates a new Logger
*
* @param prefix Log Prefix
*/
public Logger(String prefix) {
Util.nullpo(prefix);
if (prefix.length() == 0) throw new StringIndexOutOfBoundsException("Cannot use an empty prefix");
if (Util.nullpo(prefix).length() == 0) throw new StringIndexOutOfBoundsException("Cannot use an empty prefix");
debug = new LogStream(this, DEBUG);
message = new LogStream(this, MESSAGE);
info = new LogStream(this, INFO);
Expand Down
8 changes: 4 additions & 4 deletions GalaxiAPI/src/net/ME1312/Galaxi/Plugin/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ public final <T extends Event> void registerListener(PluginInfo plugin, Class<T>
* @param listeners Listeners
* @param <T> Event Type
*/
@SuppressWarnings({"unchecked", "rawtypes"})
@SuppressWarnings("rawtypes")
@SafeVarargs
public final <T extends Event> void registerListener(PluginInfo plugin, Class<T> event, Number order, Listener<? extends T>... listeners) {
Util.nullpo(plugin, event, listeners);
Util.nullpo((Object[]) listeners);
Util.nullpo(plugin, event);
Util.nullpo(listeners);
synchronized (this.listeners) {
for (Listener listener : listeners) {
try {
Expand Down Expand Up @@ -199,7 +199,7 @@ public void unregisterListeners(PluginInfo plugin) {
* @param listeners Listeners
*/
public void unregisterListeners(PluginInfo plugin, Object... listeners) {
Util.nullpo(plugin, listeners);
Util.nullpo(plugin);
Util.nullpo(listeners);
synchronized (this.listeners) {
LinkedList<Class<? extends Event>> update = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ public void run() {

"If this is not happening, for whatever reason,\n" +
"you can terminate the program from this screen.\n" +
"Terminating a program can cause some undersirable consequences,\n" +
"Terminating a program can cause some undesirable consequences,\n" +
"however, such as data loss or corruption.\n\n" +

"You can also choose to finish running the program in the background,\u00A0\u00A0\n" +
Expand Down

0 comments on commit d42418c

Please sign in to comment.