分离日志记录

This commit is contained in:
yushijinhun 2018-04-04 19:47:55 +08:00
parent c80ccccb4f
commit 5d64fc9030
No known key found for this signature in database
GPG key ID: 5BC167F73EA558E4
7 changed files with 36 additions and 21 deletions

View file

@ -6,9 +6,11 @@ import static java.util.Optional.of;
import static org.to2mbn.authlibinjector.util.IOUtils.asString;
import static org.to2mbn.authlibinjector.util.IOUtils.getURL;
import static org.to2mbn.authlibinjector.util.IOUtils.removeNewLines;
import static org.to2mbn.authlibinjector.util.LoggingUtils.debug;
import static org.to2mbn.authlibinjector.util.LoggingUtils.info;
import static org.to2mbn.authlibinjector.util.LoggingUtils.isDebugOn;
import java.io.IOException;
import java.lang.instrument.ClassFileTransformer;
import java.text.MessageFormat;
import java.util.Base64;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
@ -30,17 +32,6 @@ public final class AuthlibInjector {
private AuthlibInjector() {}
private static AtomicBoolean booted = new AtomicBoolean(false);
private static boolean debug = "true".equals(System.getProperty("org.to2mbn.authlibinjector.debug"));
public static void info(String message, Object... args) {
System.err.println("[authlib-injector] " + MessageFormat.format(message, args));
}
public static void debug(String message, Object... args) {
if (debug) {
info(message, args);
}
}
public static void bootstrap(Consumer<ClassFileTransformer> transformerRegistry) {
if (!booted.compareAndSet(false, true)) {
@ -103,7 +94,7 @@ public final class AuthlibInjector {
private static ClassTransformer createTransformer(YggdrasilConfiguration config) {
ClassTransformer transformer = new ClassTransformer();
transformer.debugSaveClass = debug;
transformer.debugSaveClass = isDebugOn();
for (String ignore : nonTransformablePackages)
transformer.ignores.add(ignore);

View file

@ -1,6 +1,6 @@
package org.to2mbn.authlibinjector.httpd;
import static org.to2mbn.authlibinjector.AuthlibInjector.info;
import static org.to2mbn.authlibinjector.util.LoggingUtils.info;
import java.io.IOException;
import org.to2mbn.authlibinjector.YggdrasilConfiguration;
import org.to2mbn.authlibinjector.transform.DeprecatedApiTransformUnit;

View file

@ -3,11 +3,11 @@ package org.to2mbn.authlibinjector.httpd;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.to2mbn.authlibinjector.AuthlibInjector.debug;
import static org.to2mbn.authlibinjector.AuthlibInjector.info;
import static org.to2mbn.authlibinjector.util.IOUtils.asString;
import static org.to2mbn.authlibinjector.util.IOUtils.getURL;
import static org.to2mbn.authlibinjector.util.IOUtils.postURL;
import static org.to2mbn.authlibinjector.util.LoggingUtils.debug;
import static org.to2mbn.authlibinjector.util.LoggingUtils.info;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UncheckedIOException;

View file

@ -1,9 +1,9 @@
package org.to2mbn.authlibinjector.javaagent;
import static org.to2mbn.authlibinjector.AuthlibInjector.bootstrap;
import static org.to2mbn.authlibinjector.AuthlibInjector.debug;
import static org.to2mbn.authlibinjector.AuthlibInjector.info;
import static org.to2mbn.authlibinjector.AuthlibInjector.nonTransformablePackages;
import static org.to2mbn.authlibinjector.util.LoggingUtils.debug;
import static org.to2mbn.authlibinjector.util.LoggingUtils.info;
import java.lang.instrument.Instrumentation;
import java.util.Arrays;

View file

@ -1,7 +1,7 @@
package org.to2mbn.authlibinjector.transform;
import static org.to2mbn.authlibinjector.AuthlibInjector.debug;
import static org.to2mbn.authlibinjector.AuthlibInjector.info;
import static org.to2mbn.authlibinjector.util.LoggingUtils.debug;
import static org.to2mbn.authlibinjector.util.LoggingUtils.info;
import java.io.IOException;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;

View file

@ -1,7 +1,7 @@
package org.to2mbn.authlibinjector.transform;
import static org.objectweb.asm.Opcodes.ASM6;
import static org.to2mbn.authlibinjector.AuthlibInjector.info;
import static org.to2mbn.authlibinjector.util.LoggingUtils.info;
import java.util.Optional;
import java.util.function.Function;
import org.objectweb.asm.ClassVisitor;

View file

@ -0,0 +1,24 @@
package org.to2mbn.authlibinjector.util;
import java.text.MessageFormat;
public final class LoggingUtils {
private static boolean debug = "true".equals(System.getProperty("org.to2mbn.authlibinjector.debug"));
public static void info(String message, Object... args) {
System.err.println("[authlib-injector] " + MessageFormat.format(message, args));
}
public static void debug(String message, Object... args) {
if (debug) {
info(message, args);
}
}
public static boolean isDebugOn() {
return debug;
}
private LoggingUtils() {}
}