add logger: launch, config

This commit is contained in:
yushijinhun 2018-07-08 15:03:09 +08:00
parent 760c90a37b
commit 177a647878
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
3 changed files with 18 additions and 16 deletions

View File

@ -68,17 +68,17 @@ public final class AuthlibInjector {
public static void bootstrap(Consumer<ClassFileTransformer> transformerRegistry) { public static void bootstrap(Consumer<ClassFileTransformer> transformerRegistry) {
if (!booted.compareAndSet(false, true)) { if (!booted.compareAndSet(false, true)) {
Logging.ROOT.info("already booted, skipping"); Logging.LAUNCH.info("already booted, skipping");
return; return;
} }
Logging.ROOT.info("version: " + getVersion()); Logging.LAUNCH.info("version: " + getVersion());
Optional<YggdrasilConfiguration> optionalConfig = configure(); Optional<YggdrasilConfiguration> optionalConfig = configure();
if (optionalConfig.isPresent()) { if (optionalConfig.isPresent()) {
transformerRegistry.accept(createTransformer(optionalConfig.get())); transformerRegistry.accept(createTransformer(optionalConfig.get()));
} else { } else {
Logging.ROOT.warning("no config available"); Logging.LAUNCH.warning("no config available");
} }
} }
@ -87,7 +87,7 @@ public final class AuthlibInjector {
if (prefetched == null) { if (prefetched == null) {
prefetched = System.getProperty(PROP_PREFETCHED_DATA_OLD); prefetched = System.getProperty(PROP_PREFETCHED_DATA_OLD);
if (prefetched != null) { if (prefetched != null) {
Logging.ROOT.warning("org.to2mbn.authlibinjector.config.prefetched option is deprecated and will be removed in a future release."); Logging.LAUNCH.warning("org.to2mbn.authlibinjector.config.prefetched option is deprecated and will be removed in a future release.");
} }
} }
return Optional.ofNullable(prefetched); return Optional.ofNullable(prefetched);
@ -96,44 +96,44 @@ public final class AuthlibInjector {
private static Optional<YggdrasilConfiguration> configure() { private static Optional<YggdrasilConfiguration> configure() {
String apiRoot = System.getProperty(PROP_API_ROOT); String apiRoot = System.getProperty(PROP_API_ROOT);
if (apiRoot == null) return empty(); if (apiRoot == null) return empty();
Logging.ROOT.info("api root: " + apiRoot); Logging.CONFIG.info("api root: " + apiRoot);
String metadataResponse; String metadataResponse;
Optional<String> prefetched = getPrefetchedResponse(); Optional<String> prefetched = getPrefetchedResponse();
if (!prefetched.isPresent()) { if (!prefetched.isPresent()) {
Logging.ROOT.info("fetching metadata"); Logging.CONFIG.info("fetching metadata");
try { try {
metadataResponse = asString(getURL(apiRoot)); metadataResponse = asString(getURL(apiRoot));
} catch (IOException e) { } catch (IOException e) {
Logging.ROOT.severe("unable to fetch metadata: " + e); Logging.CONFIG.severe("unable to fetch metadata: " + e);
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }
} else { } else {
Logging.ROOT.info("prefetched metadata detected"); Logging.CONFIG.info("prefetched metadata detected");
try { try {
metadataResponse = new String(Base64.getDecoder().decode(removeNewLines(prefetched.get())), UTF_8); metadataResponse = new String(Base64.getDecoder().decode(removeNewLines(prefetched.get())), UTF_8);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Logging.ROOT.severe("unable to decode metadata: " + e + "\n" Logging.CONFIG.severe("unable to decode metadata: " + e + "\n"
+ "metadata to decode:\n" + "metadata to decode:\n"
+ prefetched.get()); + prefetched.get());
throw e; throw e;
} }
} }
Logging.ROOT.fine("metadata: " + metadataResponse); Logging.CONFIG.fine("metadata: " + metadataResponse);
YggdrasilConfiguration configuration; YggdrasilConfiguration configuration;
try { try {
configuration = YggdrasilConfiguration.parse(apiRoot, metadataResponse); configuration = YggdrasilConfiguration.parse(apiRoot, metadataResponse);
} catch (UncheckedIOException e) { } catch (UncheckedIOException e) {
Logging.ROOT.severe("unable to parse metadata: " + e + "\n" Logging.CONFIG.severe("unable to parse metadata: " + e + "\n"
+ "metadata to parse:\n" + "metadata to parse:\n"
+ metadataResponse); + metadataResponse);
throw e; throw e;
} }
Logging.ROOT.fine("parsed metadata: " + configuration); Logging.CONFIG.fine("parsed metadata: " + configuration);
return of(configuration); return of(configuration);
} }

View File

@ -16,20 +16,20 @@ public class AuthlibInjectorPremain {
public static void premain(String arg, Instrumentation instrumentation) { public static void premain(String arg, Instrumentation instrumentation) {
try { try {
Logging.ROOT.info("launched from premain"); Logging.LAUNCH.info("launched from premain");
initInjector(arg, instrumentation, false); initInjector(arg, instrumentation, false);
} catch (Throwable e) { } catch (Throwable e) {
Logging.ROOT.log(Level.SEVERE, "an exception has been caught, exiting", e); Logging.LAUNCH.log(Level.SEVERE, "an exception has been caught, exiting", e);
System.exit(1); System.exit(1);
} }
} }
public static void agentmain(String arg, Instrumentation instrumentation) { public static void agentmain(String arg, Instrumentation instrumentation) {
try { try {
Logging.ROOT.info("launched from agentmain"); Logging.LAUNCH.info("launched from agentmain");
initInjector(arg, instrumentation, true); initInjector(arg, instrumentation, true);
} catch (Throwable e) { } catch (Throwable e) {
Logging.ROOT.log(Level.SEVERE, "an exception has been caught", e); Logging.LAUNCH.log(Level.SEVERE, "an exception has been caught", e);
} }
} }

View File

@ -14,6 +14,8 @@ public final class Logging {
private Logging() {} private Logging() {}
public static final Logger ROOT = Logger.getLogger("moe.yushi.authlibinjector"); public static final Logger ROOT = Logger.getLogger("moe.yushi.authlibinjector");
public static final Logger LAUNCH = Logger.getLogger("moe.yushi.authlibinjector.launch");
public static final Logger CONFIG = Logger.getLogger("moe.yushi.authlibinjector.config");
public static final Logger TRANSFORM = Logger.getLogger("moe.yushi.authlibinjector.transform"); public static final Logger TRANSFORM = Logger.getLogger("moe.yushi.authlibinjector.transform");
public static final Logger HTTPD = Logger.getLogger("moe.yushi.authlibinjector.httpd"); public static final Logger HTTPD = Logger.getLogger("moe.yushi.authlibinjector.httpd");