64 lines
1.7 KiB
Java
64 lines
1.7 KiB
Java
package io.github.lonamiwebs.overgram.logging;
|
|
|
|
import java.io.PrintStream;
|
|
import java.util.IllegalFormatConversionException;
|
|
|
|
public class Log {
|
|
private static final int LEVEL;
|
|
private static final PrintStream OUTPUT;
|
|
|
|
// Level - Name
|
|
// 1 - debug
|
|
// 2 - info
|
|
// 3 - warning
|
|
// 4 - error/exception
|
|
// 5 - none
|
|
static {
|
|
LEVEL = 1;
|
|
OUTPUT = System.err;
|
|
}
|
|
|
|
public static void debug(final Object message, final Object... args) {
|
|
if (LEVEL <= 1 && OUTPUT != null) {
|
|
show(message, args);
|
|
}
|
|
}
|
|
|
|
public static void info(final Object message, final Object... args) {
|
|
if (LEVEL <= 2 && OUTPUT != null) {
|
|
show(message, args);
|
|
}
|
|
}
|
|
|
|
public static void warn(final Object message, final Object... args) {
|
|
if (LEVEL <= 3 && OUTPUT != null) {
|
|
show(message, args);
|
|
}
|
|
}
|
|
|
|
public static void error(final Object message, final Object... args) {
|
|
if (LEVEL <= 4 && OUTPUT != null) {
|
|
show(message, args);
|
|
}
|
|
}
|
|
|
|
public static void exception(final Throwable exception, final Object message, final Object... args) {
|
|
if (LEVEL <= 4 && OUTPUT != null) {
|
|
show(message, args);
|
|
exception.printStackTrace(OUTPUT);
|
|
}
|
|
}
|
|
|
|
private static void show(Object message, Object... args) {
|
|
if (args.length == 0) {
|
|
OUTPUT.println(message);
|
|
} else {
|
|
try {
|
|
OUTPUT.println(String.format(message.toString(), args));
|
|
} catch (IllegalFormatConversionException ignored) {
|
|
OUTPUT.println(message);
|
|
}
|
|
}
|
|
}
|
|
}
|