|
@@ -22,40 +22,37 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.debug.commands;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.DMDircMBassador;
|
26
|
25
|
import com.dmdirc.addons.debug.Debug;
|
27
|
26
|
import com.dmdirc.addons.debug.DebugCommand;
|
28
|
27
|
import com.dmdirc.commandparser.CommandArguments;
|
29
|
28
|
import com.dmdirc.commandparser.commands.IntelligentCommand;
|
30
|
29
|
import com.dmdirc.commandparser.commands.context.CommandContext;
|
31
|
|
-import com.dmdirc.events.AppErrorEvent;
|
32
|
|
-import com.dmdirc.events.UserErrorEvent;
|
33
|
30
|
import com.dmdirc.interfaces.WindowModel;
|
34
|
|
-import com.dmdirc.logger.ErrorLevel;
|
35
|
31
|
import com.dmdirc.ui.input.AdditionalTabTargets;
|
36
|
32
|
|
37
|
33
|
import javax.annotation.Nonnull;
|
38
|
34
|
import javax.inject.Inject;
|
39
|
35
|
import javax.inject.Provider;
|
40
|
36
|
|
|
37
|
+import org.slf4j.Logger;
|
|
38
|
+import org.slf4j.LoggerFactory;
|
|
39
|
+import org.slf4j.Marker;
|
|
40
|
+
|
|
41
|
+import static com.dmdirc.util.LogUtils.APP_ERROR;
|
|
42
|
+import static com.dmdirc.util.LogUtils.FATAL_APP_ERROR;
|
|
43
|
+import static com.dmdirc.util.LogUtils.FATAL_USER_ERROR;
|
|
44
|
+import static com.dmdirc.util.LogUtils.USER_ERROR;
|
|
45
|
+
|
41
|
46
|
/**
|
42
|
47
|
* Creates DMDirc errors with the specified parameters.
|
43
|
48
|
*/
|
44
|
49
|
public class FakeError extends DebugCommand implements IntelligentCommand {
|
45
|
50
|
|
46
|
|
- /** The event bus to post errors on . */
|
47
|
|
- private final DMDircMBassador eventBus;
|
|
51
|
+ private static final Logger LOG = LoggerFactory.getLogger(FakeError.class);
|
48
|
52
|
|
49
|
|
- /**
|
50
|
|
- * Creates a new instance of the command.
|
51
|
|
- *
|
52
|
|
- * @param commandProvider The provider to use to access the main debug command.
|
53
|
|
- * @param eventBus The event bus to post errors on
|
54
|
|
- */
|
55
|
53
|
@Inject
|
56
|
|
- public FakeError(final Provider<Debug> commandProvider, final DMDircMBassador eventBus) {
|
|
54
|
+ public FakeError(final Provider<Debug> commandProvider) {
|
57
|
55
|
super(commandProvider);
|
58
|
|
- this.eventBus = eventBus;
|
59
|
56
|
}
|
60
|
57
|
|
61
|
58
|
@Override
|
|
@@ -74,19 +71,37 @@ public class FakeError extends DebugCommand implements IntelligentCommand {
|
74
|
71
|
final CommandArguments args, final CommandContext context) {
|
75
|
72
|
if ((args.getArguments().length == 1
|
76
|
73
|
|| args.getArguments().length == 2)
|
77
|
|
- && args.getArguments()[0].equals("user")) {
|
78
|
|
- eventBus.publishAsync(new UserErrorEvent(getLevel(args.getArguments()),
|
79
|
|
- null, "Debug error message", ""));
|
|
74
|
+ && "user".equals(args.getArguments()[0])) {
|
|
75
|
+ raiseError(getLevel(args.getArguments()), false);
|
80
|
76
|
} else if ((args.getArguments().length == 1
|
81
|
77
|
|| args.getArguments().length == 2)
|
82
|
|
- && args.getArguments()[0].equals("app")) {
|
83
|
|
- eventBus.publishAsync(new AppErrorEvent(getLevel(args.getArguments()),
|
84
|
|
- new IllegalArgumentException(), "Debug error message", ""));
|
|
78
|
+ && "app".equals(args.getArguments()[0])) {
|
|
79
|
+ raiseError(getLevel(args.getArguments()), true);
|
85
|
80
|
} else {
|
86
|
81
|
showUsage(origin, args.isSilent(), getName(), getUsage());
|
87
|
82
|
}
|
88
|
83
|
}
|
89
|
84
|
|
|
85
|
+ private void raiseError(final String level, final boolean appError) {
|
|
86
|
+ final Marker marker = appError ? APP_ERROR : USER_ERROR;
|
|
87
|
+ switch (level.toUpperCase()) {
|
|
88
|
+ case "FATAL":
|
|
89
|
+ LOG.error(appError ? FATAL_APP_ERROR : FATAL_USER_ERROR, "Debug error message");
|
|
90
|
+ break;
|
|
91
|
+ case "HIGH":
|
|
92
|
+ LOG.error(marker, "Debug error message");
|
|
93
|
+ break;
|
|
94
|
+ case "MEDIUM":
|
|
95
|
+ LOG.warn(marker, "Debug error message");
|
|
96
|
+ break;
|
|
97
|
+ case "INFO":
|
|
98
|
+ LOG.info(marker, "Debug error message");
|
|
99
|
+ break;
|
|
100
|
+ default:
|
|
101
|
+ LOG.info(marker, "Debug error message");
|
|
102
|
+ }
|
|
103
|
+ }
|
|
104
|
+
|
90
|
105
|
/**
|
91
|
106
|
* Returns the error level specified by the provided arguments.
|
92
|
107
|
*
|
|
@@ -94,15 +109,11 @@ public class FakeError extends DebugCommand implements IntelligentCommand {
|
94
|
109
|
*
|
95
|
110
|
* @return Error level
|
96
|
111
|
*/
|
97
|
|
- private ErrorLevel getLevel(final String... args) {
|
|
112
|
+ private String getLevel(final String... args) {
|
98
|
113
|
if (args.length >= 2) {
|
99
|
|
- try {
|
100
|
|
- return ErrorLevel.valueOf(args[1].toUpperCase());
|
101
|
|
- } catch (IllegalArgumentException ex) {
|
102
|
|
- return ErrorLevel.HIGH;
|
103
|
|
- }
|
|
114
|
+ return args[1].toUpperCase();
|
104
|
115
|
} else {
|
105
|
|
- return ErrorLevel.HIGH;
|
|
116
|
+ return "HIGH";
|
106
|
117
|
}
|
107
|
118
|
}
|
108
|
119
|
|
|
@@ -120,7 +131,6 @@ public class FakeError extends DebugCommand implements IntelligentCommand {
|
120
|
131
|
res.add("medium");
|
121
|
132
|
res.add("high");
|
122
|
133
|
res.add("fatal");
|
123
|
|
- res.add("unknown");
|
124
|
134
|
}
|
125
|
135
|
|
126
|
136
|
return res;
|