Search in sources :

Example 1 with JDALogger

use of net.dv8tion.jda.internal.utils.JDALogger in project dDiscordBot by DenizenScript.

the class DiscordConnectCommand method fixJDALogger.

/**
 * This method is a dirty hack to minimize the amount of broken output from JDA.
 */
public static void fixJDALogger() {
    if (loggerIsFixed) {
        return;
    }
    loggerIsFixed = true;
    // Dirty hack step 1: break System.err so Paper won't complain when JDALogger's static init whines into System.err
    PrintStream currentErr = System.err;
    System.setErr(altLogger);
    Logger defaultLogger = null;
    try {
        // Force JDALogger to init now, which will do that spam, and get a SimpleLogger instance while we're at it.
        defaultLogger = JDALogger.getLog(DiscordConnectCommand.class);
    } finally {
        // Fix the logger back, with a try/finally to avoid breaking it.
        System.setErr(currentErr);
    }
    try {
        // Dirty hack step 2: use that SimpleLogger instance to modify the class and redirect its log path to one that won't get complained about by Paper.
        MethodHandle streamSetter = ReflectionHelper.getFinalSetter(defaultLogger.getClass(), "TARGET_STREAM");
        streamSetter.invoke(altLogger);
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : Logger(org.slf4j.Logger) JDALogger(net.dv8tion.jda.internal.utils.JDALogger) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

MethodHandle (java.lang.invoke.MethodHandle)1 JDALogger (net.dv8tion.jda.internal.utils.JDALogger)1 Logger (org.slf4j.Logger)1