forked from wormzjl/ModularMachinery
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathLogger.java
More file actions
67 lines (56 loc) · 2.12 KB
/
Copy pathLogger.java
File metadata and controls
67 lines (56 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package github.kasuminova.mmce.common.integration;
import com.cleanroommc.groovyscript.GroovyScript;
import com.cleanroommc.groovyscript.api.GroovyLog;
import crafttweaker.CraftTweakerAPI;
import hellfirepvp.modularmachinery.ModularMachinery;
import hellfirepvp.modularmachinery.common.base.Mods;
import org.apache.logging.log4j.message.ParameterizedMessage;
/**
* A logger which logs to CraftTweaker, GroovyScript and this mods log, depending on if the mods are loaded.
*/
public class Logger {
private static final String CT_PREFIX = "[ModularMachinery] ";
private static final Object[] NO_ARGS = new Object[0];
private static boolean isGroovyScriptRunning() {
return Mods.GROOVYSCRIPT.isPresent() && GroovyScript.getSandbox().isRunning();
}
private static String formatMsg(String msg, Object... args) {
return args == null || args.length == 0 ? msg : new ParameterizedMessage(msg, args).getFormattedMessage();
}
public static void error(String msg) {
error(msg, NO_ARGS);
}
public static void warn(String msg) {
warn(msg, NO_ARGS);
}
public static void info(String msg) {
info(msg, NO_ARGS);
}
public static void error(String msg, Object... args) {
if (isGroovyScriptRunning()) {
GroovyLog.get().error(msg, args);
}
if (Mods.CRAFTTWEAKER.isPresent()) {
CraftTweakerAPI.logError(CT_PREFIX + formatMsg(msg, args));
}
ModularMachinery.log.error(msg, args);
}
public static void warn(String msg, Object... args) {
if (isGroovyScriptRunning()) {
GroovyLog.get().warn(msg, args);
}
if (Mods.CRAFTTWEAKER.isPresent()) {
CraftTweakerAPI.logWarning(formatMsg(msg, args));
}
ModularMachinery.log.warn(msg, args);
}
public static void info(String msg, Object... args) {
if (isGroovyScriptRunning()) {
GroovyLog.get().info(msg, args);
}
if (Mods.CRAFTTWEAKER.isPresent()) {
CraftTweakerAPI.logInfo(formatMsg(msg, args));
}
ModularMachinery.log.info(msg, args);
}
}