Log thread in verbose events

This commit is contained in:
Luck 2019-11-23 17:26:48 +00:00
parent 479b2d026c
commit 94418d3648
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
6 changed files with 25 additions and 19 deletions

View File

@ -447,7 +447,7 @@ public enum Message {
LOG_EXPORT_NOT_WRITABLE("&cError: File &4{}&c is not writable.", true), LOG_EXPORT_NOT_WRITABLE("&cError: File &4{}&c is not writable.", true),
LOG_EXPORT_EMPTY("&cThe log is empty and therefore cannot be exported.", true), LOG_EXPORT_EMPTY("&cThe log is empty and therefore cannot be exported.", true),
LOG_EXPORT_FAILURE("&cAn unexpected error occured whilst writing to the file.", true), LOG_EXPORT_FAILURE("&cAn unexpected error occured whilst writing to the file.", true),
LOG_EXPORT_SUCCESS("&aSuccessfully exported the log to &b{}&a.", true), LOG_EXPORT_SUCCESS("&aSuccessfully exported to &b{}&a.", true),
IMPORT_ALREADY_RUNNING("&cAnother import process is already running. Please wait for it to finish and try again.", true), IMPORT_ALREADY_RUNNING("&cAnother import process is already running. Please wait for it to finish and try again.", true),
EXPORT_ALREADY_RUNNING("&cAnother export process is already running. Please wait for it to finish and try again.", true), EXPORT_ALREADY_RUNNING("&cAnother export process is already running. Please wait for it to finish and try again.", true),

View File

@ -81,9 +81,10 @@ public class VerboseHandler extends RepeatingTask {
} }
StackTraceElement[] trace = new Exception().getStackTrace(); StackTraceElement[] trace = new Exception().getStackTrace();
String thread = Thread.currentThread().getName();
// add the check data to a queue to be processed later. // add the check data to a queue to be processed later.
this.queue.offer(new PermissionCheckEvent(origin, checkTarget, checkQueryOptions, trace, permission, result)); this.queue.offer(new PermissionCheckEvent(origin, checkTarget, checkQueryOptions, trace, thread, permission, result));
} }
/** /**
@ -105,9 +106,10 @@ public class VerboseHandler extends RepeatingTask {
} }
StackTraceElement[] trace = new Exception().getStackTrace(); StackTraceElement[] trace = new Exception().getStackTrace();
String thread = Thread.currentThread().getName();
// add the check data to a queue to be processed later. // add the check data to a queue to be processed later.
this.queue.offer(new MetaCheckEvent(origin, checkTarget, checkQueryOptions, trace, key, result)); this.queue.offer(new MetaCheckEvent(origin, checkTarget, checkQueryOptions, trace, thread, key, result));
} }
/** /**

View File

@ -45,8 +45,8 @@ import me.lucko.luckperms.common.web.BytebinClient;
import net.kyori.text.TextComponent; import net.kyori.text.TextComponent;
import net.kyori.text.event.HoverEvent; import net.kyori.text.event.HoverEvent;
import net.luckperms.api.util.Tristate;
import net.luckperms.api.query.QueryMode; import net.luckperms.api.query.QueryMode;
import net.luckperms.api.util.Tristate;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -217,6 +217,7 @@ public class VerboseListener {
if (event.getCheckQueryOptions().mode() == QueryMode.CONTEXTUAL) { if (event.getCheckQueryOptions().mode() == QueryMode.CONTEXTUAL) {
hover.add("&bContext: &r" + MessageUtils.contextSetToString(this.notifiedSender.getPlugin().getLocaleManager(), event.getCheckQueryOptions().context())); hover.add("&bContext: &r" + MessageUtils.contextSetToString(this.notifiedSender.getPlugin().getLocaleManager(), event.getCheckQueryOptions().context()));
} }
hover.add("&bThread: &r" + event.getCheckThread());
hover.add("&bTrace: &r"); hover.add("&bTrace: &r");
Consumer<StackTraceElement> printer = StackTracePrinter.elementToString(str -> hover.add("&7" + str)); Consumer<StackTraceElement> printer = StackTracePrinter.elementToString(str -> hover.add("&7" + str));

View File

@ -46,8 +46,8 @@ public class MetaCheckEvent extends VerboseEvent {
*/ */
private final String result; private final String result;
public MetaCheckEvent(Origin origin, String checkTarget, QueryOptions checkQueryOptions, StackTraceElement[] checkTrace, String key, String result) { public MetaCheckEvent(Origin origin, String checkTarget, QueryOptions checkQueryOptions, StackTraceElement[] checkTrace, String checkThread, String key, String result) {
super(checkTarget, checkQueryOptions, checkTrace); super(checkTarget, checkQueryOptions, checkTrace, checkThread);
this.origin = origin; this.origin = origin;
this.key = key; this.key = key;
this.result = result; this.result = result;

View File

@ -47,8 +47,8 @@ public class PermissionCheckEvent extends VerboseEvent {
*/ */
private final TristateResult result; private final TristateResult result;
public PermissionCheckEvent(Origin origin, String checkTarget, QueryOptions checkQueryOptions, StackTraceElement[] checkTrace, String permission, TristateResult result) { public PermissionCheckEvent(Origin origin, String checkTarget, QueryOptions checkQueryOptions, StackTraceElement[] checkTrace, String checkThread, String permission, TristateResult result) {
super(checkTarget, checkQueryOptions, checkTrace); super(checkTarget, checkQueryOptions, checkTrace, checkThread);
this.origin = origin; this.origin = origin;
this.permission = permission; this.permission = permission;
this.result = result; this.result = result;

View File

@ -58,10 +58,16 @@ public abstract class VerboseEvent implements VariableEvaluator {
*/ */
private final StackTraceElement[] checkTrace; private final StackTraceElement[] checkTrace;
protected VerboseEvent(String checkTarget, QueryOptions checkQueryOptions, StackTraceElement[] checkTrace) { /**
* The name of the thread where the check took place
*/
private final String checkThread;
protected VerboseEvent(String checkTarget, QueryOptions checkQueryOptions, StackTraceElement[] checkTrace, String checkThread) {
this.checkTarget = checkTarget; this.checkTarget = checkTarget;
this.checkQueryOptions = checkQueryOptions; this.checkQueryOptions = checkQueryOptions;
this.checkTrace = checkTrace; this.checkTrace = checkTrace;
this.checkThread = checkThread;
} }
public String getCheckTarget() { public String getCheckTarget() {
@ -76,9 +82,13 @@ public abstract class VerboseEvent implements VariableEvaluator {
return this.checkTrace; return this.checkTrace;
} }
public String getCheckThread() {
return this.checkThread;
}
protected abstract void serializeTo(JObject object); protected abstract void serializeTo(JObject object);
private JObject formBaseJson() { public JsonObject toJson(StackTracePrinter tracePrinter) {
return new JObject() return new JObject()
.add("who", new JObject() .add("who", new JObject()
.add("identifier", this.checkTarget) .add("identifier", this.checkTarget)
@ -95,15 +105,6 @@ public abstract class VerboseEvent implements VariableEvaluator {
); );
} }
}) })
.consume(this::serializeTo);
}
public JsonObject toJson() {
return formBaseJson().toJson();
}
public JsonObject toJson(StackTracePrinter tracePrinter) {
return formBaseJson()
.add("trace", new JArray() .add("trace", new JArray()
.consume(arr -> { .consume(arr -> {
int overflow = tracePrinter.process(this.checkTrace, StackTracePrinter.elementToString(arr::add)); int overflow = tracePrinter.process(this.checkTrace, StackTracePrinter.elementToString(arr::add));
@ -112,6 +113,8 @@ public abstract class VerboseEvent implements VariableEvaluator {
} }
}) })
) )
.add("thread", this.checkThread)
.consume(this::serializeTo)
.toJson(); .toJson();
} }
} }