Merge remote-tracking branch 'sponge/0.8.4'

# Conflicts:
#	build.gradle
#	src/main/java/org/spongepowered/asm/mixin/refmap/RemappingReferenceMapper.java
#	src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java
This commit is contained in:
modmuss50 committed 2021-08-18 21:24:16 +01:00
commit 913050a85e
63 files changed
+1372 -251

No files matched your search

+27 -50
View File
@@ -69,7 +69,7 @@ repositories {
configurations {
stagingJar
exampleImplementation .extendsFrom implementation
fernflowerImplementation .extendsFrom implementation
launchwrapperImplementation .extendsFrom implementation
@@ -84,31 +84,36 @@ configurations {
extendsFrom modlauncherImplementation
extendsFrom compileClasspath
}
tinyRemapper
}
sourceSets {
legacy {
ext.compatibility = '1.8'
ext.languageVersion = 8
ext.compatibility = '1.6'
}
main {
compileClasspath += legacy.output
ext.compatibility = '1.8'
ext.languageVersion = 8
ext.compatibility = '1.6'
}
ap {
compileClasspath += main.output
ext.compatibility = '1.8'
ext.languageVersion = 8
ext.compatibility = '1.6'
}
fernflower {
compileClasspath += main.output
ext.compatibility = '1.8'
ext.languageVersion = 8
ext.compatibility = '1.6'
}
agent {
compileClasspath += main.output
ext.compatibility = '1.8'
ext.languageVersion = 8
ext.compatibility = '1.6'
}
bridge {
compileClasspath += main.output
ext.languageVersion = 8
ext.compatibility = '1.8'
}
example {
@@ -117,15 +122,18 @@ sourceSets {
}
launchwrapper {
compileClasspath += main.output
ext.languageVersion = 8
ext.compatibility = '1.8'
}
modlauncher {
compileClasspath += main.output
ext.languageVersion = 8
ext.compatibility = '1.8'
}
modlauncher4 {
compileClasspath += main.output
compileClasspath += modlauncher.output
ext.languageVersion = 8
ext.compatibility = '1.8'
}
modlauncher9 {
@@ -149,16 +157,12 @@ sourceSets {
// Project dependencies
dependencies {
def guava = 'com.google.guava:guava:21.0' // from mc1.12 onwards
def log4j2 = 'org.apache.logging.log4j:log4j-core:2.0-beta9'
def log4j2Modular = 'org.apache.logging.log4j:log4j-core:2.11.2'
def gson = 'com.google.code.gson:gson:2.2.4'
stagingJar guava
stagingJar gson
implementation guava
implementation log4j2
modularityImplementation log4j2Modular
implementation 'com.google.code.gson:gson:2.2.4'
if (Float.parseFloat(asmVersion) < 6) {
implementation "org.ow2.asm:asm-debug-all:$asmVersion"
@@ -170,7 +174,7 @@ dependencies {
// Annotation Processor
apImplementation "org.ow2.asm:asm-tree:$asmVersion"
apImplementation guava
// Fernflower decompiler
fernflowerImplementation 'org.jetbrains:intellij-fernflower:1.0.0.9'
@@ -180,42 +184,37 @@ dependencies {
exclude module: 'asm-debug-all'
exclude module: 'jopt-simple'
}
modlauncherImplementation 'net.sf.jopt-simple:jopt-simple:5.0.4'
modlauncherCompileOnly 'org.apache.logging.log4j:log4j-core:2.0-beta9'
modlauncherImplementation ("cpw.mods:modlauncher:$legacyModlauncherVersion") {
exclude module: 'asm'
exclude module: 'asm-analysis'
exclude module: 'asm-commons'
exclude module: 'asm-tree'
exclude module: 'log4j-api'
exclude module: 'log4j-core'
exclude module: 'jopt-simple'
}
modlauncher4Implementation ("cpw.mods:modlauncher:$legacyModlauncherVersion") {
exclude module: 'asm'
exclude module: 'asm-analysis'
exclude module: 'asm-commons'
exclude module: 'asm-tree'
exclude module: 'log4j-api'
exclude module: 'log4j-core'
exclude module: 'jopt-simple'
}
modlauncher9Implementation ("cpw.mods:modlauncher:$modlauncherVersion") {
exclude module: 'log4j-api'
exclude module: 'log4j-core'
exclude module: 'jopt-simple'
}
modlauncher9Implementation 'cpw.mods:securejarhandler:0.9.+'
// asm bridge
bridgeImplementation log4j2
bridgeImplementation 'org.apache.logging.log4j:log4j-core:2.0-beta9'
bridgeImplementation "org.ow2.asm:asm-commons:$legacyForgeAsmVersion"
legacyImplementation "org.ow2.asm:asm-tree:$asmVersion"
tinyRemapper "net.fabricmc:tiny-remapper:0.4.2"
modularityCompileOnly 'org.apache.logging.log4j:log4j-core:2.11.2'
}
compileModularityJava {
@@ -254,6 +253,7 @@ eclipse {
// Can't include old modlauncher because it causes issues with modules
entries.removeAll { it.kind == 'lib' && it.path =~ ~/modlauncher-$legacyModlauncherVersion/ }
entries.removeAll { it.kind == 'src' && it.path =~ ~/modlauncher4/ }
entries.removeAll { it.kind == 'lib' && it.path =~ ~/log4j.*beta9/ }
// Mark everything else as a module
entries.findAll { it.kind == "con" && it.path =~ /gradleclasspathcontainer$/ }.each {
@@ -310,7 +310,7 @@ project.sourceSets.each { set -> {
project.tasks[set.compileJavaTaskName].javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(set.ext.languageVersion)
}
}
}
if (set.ext.has("compatibility")) {
project.tasks[set.compileJavaTaskName].sourceCompatibility = set.ext.compatibility
project.tasks[set.compileJavaTaskName].targetCompatibility = set.ext.compatibility
@@ -329,7 +329,7 @@ task stagingJar(type: ShadowJar) {
from it.output
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
configurations = [project.configurations.stagingJar]
// JAR manifest configuration
@@ -351,8 +351,7 @@ task stagingJar(type: ShadowJar) {
archiveClassifier = "staging"
}
File proguardFile = file("build/libs/sponge-mixin-${version}-universal.jar")
File remappedFile = file("build/libs/sponge-mixin-${version}.jar")
File proguardFile = file("build/libs/sponge-mixin-${version}.jar")
task stagingProguardJar(type: proguard.gradle.ProGuardTask, dependsOn: stagingJar) {
doFirst {
@@ -370,23 +369,6 @@ task stagingProguardJar(type: proguard.gradle.ProGuardTask, dependsOn: stagingJa
configuration file("proguard.conf")
}
// Remap log4j usage to use fabric-loaders bridge
task remapLog4jUsage(type: JavaExec, dependsOn: stagingProguardJar) {
classpath = configurations.tinyRemapper
mainClass = "net.fabricmc.tinyremapper.Main"
outputs.upToDateWhen { false }
args = [
proguardFile.absolutePath,
remappedFile.absolutePath,
file("log4j.mappings").absolutePath,
"log4j",
"loader"
]
}
build.dependsOn remapLog4jUsage
// Clear artifacts because jar will be there by default and we want to use staging jar instead
configurations.archives.artifacts.clear()
@@ -446,11 +428,6 @@ publishing {
artifact javadocJar
artifact(proguardFile) {
builtBy stagingProguardJar
classifier = "universal"
}
artifact(remappedFile) {
builtBy remapLog4jUsage
classifier = null
}
@@ -32,8 +32,7 @@ import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.transformer.IMixinTransformer;
@@ -77,10 +76,10 @@ public class MixinAgent implements IHotSwap {
}
try {
MixinAgent.logger.info("Redefining class " + className);
MixinAgent.logger.info("Redefining class {}", className);
return MixinAgent.this.classTransformer.transformClassBytes(null, className, classfileBuffer);
} catch (Throwable th) {
MixinAgent.logger.error("Error while re-transforming class " + className, th);
MixinAgent.logger.error("Error while re-transforming class {}", className, th);
return MixinAgent.ERROR_BYTECODE;
}
}
@@ -93,7 +92,7 @@ public class MixinAgent implements IHotSwap {
MixinAgent.logger.error("Mixin {} cannot be reloaded, needs a restart to be applied: {} ", e.getMixinInfo(), e.getMessage());
} catch (Throwable th) {
// catch everything as otherwise it is ignored
MixinAgent.logger.error("Error while finding targets for mixin " + className, th);
MixinAgent.logger.error("Error while finding targets for mixin {}", className, th);
}
return null;
}
@@ -121,7 +120,7 @@ public class MixinAgent implements IHotSwap {
targetBytecode = MixinAgent.this.classTransformer.transformClassBytes(null, targetName, targetBytecode);
MixinAgent.instrumentation.redefineClasses(new ClassDefinition(targetClass, targetBytecode));
} catch (Throwable th) {
MixinAgent.logger.error("Error while re-transforming target class " + target, th);
MixinAgent.logger.error("Error while re-transforming target class {}", target, th);
return false;
}
}
@@ -141,7 +140,7 @@ public class MixinAgent implements IHotSwap {
*/
static final MixinAgentClassLoader classLoader = new MixinAgentClassLoader();
static final Logger logger = LogManager.getLogger("mixin.agent");
static final ILogger logger = MixinService.getService().getLogger("mixin.agent");
/**
* Instance used to register the transformer
@@ -27,14 +27,14 @@ package org.spongepowered.tools.agent;
import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Constants;
/**
@@ -43,7 +43,7 @@ import org.spongepowered.asm.util.Constants;
*/
class MixinAgentClassLoader extends ClassLoader {
private static final Logger logger = LogManager.getLogger("mixin.agent");
private static final ILogger logger = MixinService.getService().getLogger("mixin.agent");
/**
* Mapping of mixin mixin classes to their fake classes
@@ -93,7 +93,7 @@ class MixinAgentClassLoader extends ClassLoader {
} catch (Exception ex) {
MixinAgentClassLoader.logger.error("Error storing original class bytecode for {} in mixin hotswap agent. {}: {}",
name, ex.getClass().getName(), ex.getMessage());
MixinAgentClassLoader.logger.debug(ex);
MixinAgentClassLoader.logger.debug(ex.toString());
}
}
}
@@ -24,10 +24,10 @@
*/
package org.spongepowered.asm.bridge;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.commons.Remapper;
import org.spongepowered.asm.mixin.extensibility.IRemapper;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.ObfuscationUtil;
import org.spongepowered.asm.util.ObfuscationUtil.IClassRemapper;
@@ -36,7 +36,7 @@ import org.spongepowered.asm.util.ObfuscationUtil.IClassRemapper;
*/
public abstract class RemapperAdapter implements IRemapper, IClassRemapper {
protected final Logger logger = LogManager.getLogger("mixin");
protected final ILogger logger = MixinService.getService().getLogger("mixin");
protected final org.objectweb.asm.commons.Remapper remapper;
public RemapperAdapter(Remapper remapper) {
@@ -31,9 +31,8 @@ import java.net.URL;
import java.util.Map;
import java.util.jar.Manifest;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.Level;
import org.spongepowered.asm.logging.ILogger;
import org.jetbrains.java.decompiler.main.Fernflower;
import org.jetbrains.java.decompiler.main.extern.IBytecodeProvider;
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger;
@@ -41,6 +40,7 @@ import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import org.jetbrains.java.decompiler.main.extern.IResultSaver;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
import org.spongepowered.asm.mixin.transformer.ext.IDecompiler;
import org.spongepowered.asm.service.MixinService;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
@@ -67,7 +67,7 @@ public class RuntimeDecompiler extends IFernflowerLogger implements IDecompiler,
private final File outputPath;
protected final Logger logger = LogManager.getLogger("fernflower");
protected final ILogger logger = MixinService.getService().getLogger("fernflower");
public RuntimeDecompiler(File outputPath) {
this.outputPath = outputPath;
@@ -382,7 +382,7 @@ public class MixinPlatformAgentFMLLegacy extends MixinPlatformAgentAbstract impl
// Legacy name
mdGetIgnoredMods = clCoreModManager.getDeclaredMethod(MixinPlatformAgentFMLLegacy.GET_IGNORED_MODS_METHOD_LEGACY);
} catch (NoSuchMethodException ex2) {
MixinPlatformAgentAbstract.logger.catching(Level.DEBUG, ex2);
MixinPlatformAgentAbstract.logger.catching(org.spongepowered.asm.logging.Level.DEBUG, ex2);
return Collections.<String>emptyList();
}
}
@@ -27,8 +27,8 @@ package org.spongepowered.asm.mixin.transformer;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.spongepowered.asm.service.ILegacyClassTransformer;
import org.spongepowered.asm.service.MixinService;
import net.minecraft.launchwrapper.IClassTransformer;
@@ -63,7 +63,7 @@ public final class Proxy implements IClassTransformer, ILegacyClassTransformer {
}
Proxy.proxies.add(this);
LogManager.getLogger("mixin").debug("Adding new mixin transformer proxy #{}", Proxy.proxies.size());
MixinService.getService().getLogger("mixin").debug("Adding new mixin transformer proxy #{}", Proxy.proxies.size());
}
@Override
@@ -0,0 +1,140 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.asm.service.mojang;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.Level;
import org.spongepowered.asm.logging.LoggerAdapterAbstract;
public class LoggerAdapterLog4j2 extends LoggerAdapterAbstract {
private static final org.apache.logging.log4j.Level[] LEVELS = {
/* FATAL = */ org.apache.logging.log4j.Level.FATAL,
/* ERROR = */ org.apache.logging.log4j.Level.ERROR,
/* WARN = */ org.apache.logging.log4j.Level.WARN,
/* INFO = */ org.apache.logging.log4j.Level.INFO,
/* DEBUG = */ org.apache.logging.log4j.Level.DEBUG,
/* TRACE = */ org.apache.logging.log4j.Level.TRACE
};
private final Logger logger;
public LoggerAdapterLog4j2(String name) {
super(name);
this.logger = LogManager.getLogger(name);
}
@Override
public String getType() {
return "Log4j2 (via LaunchWrapper)";
}
@Override
public void catching(Level level, Throwable t) {
this.logger.catching(LoggerAdapterLog4j2.LEVELS[level.ordinal()], t);
}
@Override
public void catching(Throwable t) {
this.logger.catching(t);
}
@Override
public void debug(String message, Object... params) {
this.logger.debug(message, params);
}
@Override
public void debug(String message, Throwable t) {
this.logger.debug(message, t);
}
@Override
public void error(String message, Object... params) {
this.logger.error(message, params);
}
@Override
public void error(String message, Throwable t) {
this.logger.error(message, t);
}
@Override
public void fatal(String message, Object... params) {
this.logger.fatal(message, params);
}
@Override
public void fatal(String message, Throwable t) {
this.logger.fatal(message, t);
}
@Override
public void info(String message, Object... params) {
this.logger.info(message, params);
}
@Override
public void info(String message, Throwable t) {
this.logger.info(message, t);
}
@Override
public void log(Level level, String message, Object... params) {
this.logger.log(LoggerAdapterLog4j2.LEVELS[level.ordinal()], message, params);
}
@Override
public void log(Level level, String message, Throwable t) {
this.logger.log(LoggerAdapterLog4j2.LEVELS[level.ordinal()], message, t);
}
@Override
public <T extends Throwable> T throwing(T t) {
return this.logger.throwing(t);
}
@Override
public void trace(String message, Object... params) {
this.logger.trace(message, params);
}
@Override
public void trace(String message, Throwable t) {
this.logger.trace(message, t);
}
@Override
public void warn(String message, Object... params) {
this.logger.warn(message, params);
}
@Override
public void warn(String message, Throwable t) {
this.logger.warn(message, t);
}
}
@@ -38,6 +38,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.launch.GlobalProperties;
@@ -46,6 +48,7 @@ import org.spongepowered.asm.launch.platform.MainAttributes;
import org.spongepowered.asm.launch.platform.container.ContainerHandleURI;
import org.spongepowered.asm.launch.platform.container.ContainerHandleVirtual;
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
@@ -98,6 +101,11 @@ public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements I
"net.minecraftforge.fml.common.asm.transformers.TerminalTransformer",
"cpw.mods.fml.common.asm.transformers.TerminalTransformer"
);
/**
* Log4j2 logger
*/
private static final Logger logger = LogManager.getLogger();
/**
* Utility for reflecting into Launch ClassLoader
@@ -173,6 +181,11 @@ public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements I
public CompatibilityLevel getMaxCompatibilityLevel() {
return CompatibilityLevel.JAVA_8;
}
@Override
protected ILogger createLogger(String name) {
return new LoggerAdapterLog4j2(name);
}
/* (non-Javadoc)
* @see org.spongepowered.asm.service.IMixinService#init()
@@ -180,7 +193,7 @@ public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements I
@Override
public void init() {
if (MixinServiceLaunchWrapper.findInStackTrace("net.minecraft.launchwrapper.Launch", "launch") < 4) {
MixinServiceAbstract.logger.error("MixinBootstrap.doInit() called during a tweak constructor!");
MixinServiceLaunchWrapper.logger.error("MixinBootstrap.doInit() called during a tweak constructor!");
}
List<String> tweakClasses = GlobalProperties.<List<String>>get(MixinServiceLaunchWrapper.BLACKBOARD_KEY_TWEAKCLASSES);
@@ -231,7 +244,7 @@ public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements I
for (URL url : sources) {
try {
URI uri = url.toURI();
MixinServiceAbstract.logger.debug("Scanning {} for mixin tweaker", uri);
MixinServiceLaunchWrapper.logger.debug("Scanning {} for mixin tweaker", uri);
if (!"file".equals(uri.getScheme()) || !new File(uri).exists()) {
continue;
}
@@ -367,7 +380,7 @@ public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements I
}
if (transformer instanceof IClassNameTransformer) {
MixinServiceAbstract.logger.debug("Found name transformer: {}", transformer.getClass().getName());
MixinServiceLaunchWrapper.logger.debug("Found name transformer: {}", transformer.getClass().getName());
this.nameTransformer = (IClassNameTransformer)transformer;
}
@@ -401,7 +414,7 @@ public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements I
* list just once per environment and cache the result.
*/
private void buildTransformerDelegationList() {
MixinServiceAbstract.logger.debug("Rebuilding transformer delegation list:");
MixinServiceLaunchWrapper.logger.debug("Rebuilding transformer delegation list:");
this.delegatedTransformers = new ArrayList<ILegacyClassTransformer>();
for (ITransformer transformer : this.getTransformers()) {
if (!(transformer instanceof ILegacyClassTransformer)) {
@@ -418,14 +431,14 @@ public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements I
}
}
if (include && !legacyTransformer.isDelegationExcluded()) {
MixinServiceAbstract.logger.debug(" Adding: {}", transformerName);
MixinServiceLaunchWrapper.logger.debug(" Adding: {}", transformerName);
this.delegatedTransformers.add(legacyTransformer);
} else {
MixinServiceAbstract.logger.debug(" Excluding: {}", transformerName);
MixinServiceLaunchWrapper.logger.debug(" Excluding: {}", transformerName);
}
}
MixinServiceAbstract.logger.debug("Transformer delegation list created with {} entries", this.delegatedTransformers.size());
MixinServiceLaunchWrapper.logger.debug("Transformer delegation list created with {} entries", this.delegatedTransformers.size());
}
/**
@@ -541,7 +554,7 @@ public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements I
this.addTransformerExclusion(transformer.getName());
this.lock.clear();
MixinServiceAbstract.logger.info("A re-entrant transformer '{}' was detected and will no longer process meta class data",
MixinServiceLaunchWrapper.logger.info("A re-entrant transformer '{}' was detected and will no longer process meta class data",
transformer.getName());
}
}
@@ -565,7 +578,7 @@ public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements I
List<IClassTransformer> transformers = Launch.classLoader.getTransformers();
for (IClassTransformer transformer : transformers) {
if (transformer instanceof IClassNameTransformer) {
MixinServiceAbstract.logger.debug("Found name transformer: {}", transformer.getClass().getName());
MixinServiceLaunchWrapper.logger.debug("Found name transformer: {}", transformer.getClass().getName());
this.nameTransformer = (IClassNameTransformer) transformer;
}
}
@@ -36,6 +36,7 @@ public class MixinServiceLaunchWrapperBootstrap implements IMixinServiceBootstra
private static final String SERVICE_PACKAGE = "org.spongepowered.asm.service.";
private static final String LAUNCH_PACKAGE = "org.spongepowered.asm.launch.";
private static final String LOGGING_PACKAGE = "org.spongepowered.asm.logging.";
private static final String MIXIN_UTIL_PACKAGE = "org.spongepowered.asm.util.";
private static final String LEGACY_ASM_PACKAGE = "org.spongepowered.asm.lib.";
@@ -63,6 +64,7 @@ public class MixinServiceLaunchWrapperBootstrap implements IMixinServiceBootstra
// Essential ones
Launch.classLoader.addClassLoaderExclusion(MixinServiceLaunchWrapperBootstrap.SERVICE_PACKAGE);
Launch.classLoader.addClassLoaderExclusion(MixinServiceLaunchWrapperBootstrap.LAUNCH_PACKAGE);
Launch.classLoader.addClassLoaderExclusion(MixinServiceLaunchWrapperBootstrap.LOGGING_PACKAGE);
// Important ones
Launch.classLoader.addClassLoaderExclusion(MixinServiceLaunchWrapperBootstrap.ASM_PACKAGE);
@@ -28,8 +28,7 @@ import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.launch.platform.CommandLineOptions;
import org.spongepowered.asm.launch.platform.MixinPlatformManager;
import org.spongepowered.asm.mixin.MixinEnvironment;
@@ -73,20 +72,21 @@ public abstract class MixinBootstrap {
*/
private static final String MIXIN_TRANSFORMER_FACTORY_CLASS = "org.spongepowered.asm.mixin.transformer.MixinTransformer$Factory";
/**
* Log all the things
*/
private static final Logger logger = LogManager.getLogger("mixin");
// These are Klass local, with luck this shouldn't be a problem
private static boolean initialised = false;
private static boolean initState = true;
/**
* Log all the things
*/
private static ILogger logger;
// Static initialiser, run boot services as early as possible
static {
MixinService.boot();
MixinService.getService().prepare();
MixinBootstrap.logger = MixinService.getService().getLogger("mixin");
}
/**
@@ -179,7 +179,7 @@ public abstract class MixinBootstrap {
static void doInit(CommandLineOptions args) {
if (!MixinBootstrap.initialised) {
if (MixinBootstrap.isSubsystemRegistered()) {
MixinBootstrap.logger.warn("Multiple Mixin containers present, init suppressed for " + MixinBootstrap.VERSION);
MixinBootstrap.logger.warn("Multiple Mixin containers present, init suppressed for {}", MixinBootstrap.VERSION);
return;
}
@@ -29,8 +29,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.mixin.connect.IMixinConnector;
import org.spongepowered.asm.service.IClassProvider;
import org.spongepowered.asm.service.MixinService;
@@ -43,7 +42,7 @@ public class MixinConnectorManager {
/**
* Logging to the max
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
private final Set<String> connectorClasses = new LinkedHashSet<String>();
@@ -82,9 +81,9 @@ public class MixinConnectorManager {
try {
IMixinConnector connector = connectorClass.getDeclaredConstructor().newInstance();
this.connectors.add(connector);
MixinConnectorManager.logger.info("Successfully loaded Mixin Connector [" + connectorClassName + "]");
MixinConnectorManager.logger.info("Successfully loaded Mixin Connector [{}]", connectorClassName);
} catch (ReflectiveOperationException ex) {
MixinConnectorManager.logger.warn("Error loading Mixin Connector [" + connectorClassName + "]", ex);
MixinConnectorManager.logger.warn("Error loading Mixin Connector [{}]", connectorClassName, ex);
}
}
this.connectorClasses.clear();
@@ -30,8 +30,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.launch.GlobalProperties;
import org.spongepowered.asm.launch.platform.IMixinPlatformAgent.AcceptResult;
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
@@ -53,7 +52,7 @@ public class MixinContainer {
MixinContainer.agentClasses.add("org.spongepowered.asm.launch.platform.MixinPlatformAgentDefault");
}
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
private final IContainerHandle handle;
@@ -26,10 +26,10 @@ package org.spongepowered.asm.launch.platform;
import java.lang.reflect.Method;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.IConsumer;
/**
@@ -40,7 +40,7 @@ public abstract class MixinPlatformAgentAbstract implements IMixinPlatformAgent
/**
* Logger
*/
protected static final Logger logger = LogManager.getLogger("mixin");
protected static final ILogger logger = MixinService.getService().getLogger("mixin");
protected MixinPlatformManager manager;
@@ -32,8 +32,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
@@ -56,7 +55,7 @@ public class MixinPlatformManager {
/**
* Make with the logging already
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Bootstrap delegate
@@ -0,0 +1,188 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.asm.logging;
/**
* Interface extracted from Log4j2's Logger (<tt>org.apache.logging.log4j.Logger
* </tt>) with only the main methods used by Mixin included. This is to
* facilitate the delegation of logging to mixin services, and to sever the
* dependency on log4j2 from Mixin's core.
*/
public interface ILogger {
/**
* Get the id of this logger
*/
public abstract String getId();
/**
* Get a short human-readable name of this logger type
*/
public abstract String getType();
/**
* Logs an exception or error that has been caught.
*
* @param level The logging Level.
* @param t The Throwable.
*/
public abstract void catching(Level level, Throwable t);
/**
* Logs an exception or error that has been caught.
* @param t The Throwable.
*/
public abstract void catching(Throwable t);
/**
* Logs a message with parameters at the {@link Level#DEBUG DEBUG} level.
*
* @param message the message to log
* @param params parameters to the message
*/
public abstract void debug(String message, Object... params);
/**
* Logs a message at the {@link Level#DEBUG DEBUG} level including the
* stack trace of the {@link Throwable} <code>t</code> passed as parameter.
*
* @param message the message to log
* @param t the exception to log, including its stack trace
*/
public abstract void debug(String message, Throwable t);
/**
* Logs a message with parameters at the {@link Level#ERROR ERROR} level
*
* @param message the message to log
* @param params parameters to the message
*/
public abstract void error(String message, Object... params);
/**
* Logs a message at the {@link Level#ERROR ERROR} level including the
* stack trace of the {@link Throwable} <code>t</code> passed as parameter.
*
* @param message the message object to log
* @param t the exception to log, including its stack trace
*/
public abstract void error(String message, Throwable t);
/**
* Logs a message with parameters at the {@link Level#FATAL FATAL} level.
*
* @param message the message to log
* @param params parameters to the message
*/
void fatal(String message, Object... params);
/**
* Logs a message at the {@link Level#FATAL FATAL} level including the
* stack trace of the {@link Throwable} <code>t</code> passed as parameter.
*
* @param message the message object to log
* @param t the exception to log, including its stack trace
*/
void fatal(String message, Throwable t);
/**
* Logs a message with parameters at the {@link Level#INFO INFO} level.
*
* @param message the message to log
* @param params parameters to the message
*/
public abstract void info(String message, Object... params);
/**
* Logs a message at the {@link Level#INFO INFO} level including the
* stack trace of the {@link Throwable} <code>t</code> passed as parameter.
*
* @param message the message object to log
* @param t the exception to log, including its stack trace
*/
public abstract void info(String message, Throwable t);
/**
* Logs a message with parameters at the given level.
*
* @param level the logging level
* @param message the message to log
* @param params parameters to the message
*/
public abstract void log(Level level, String message, Object... params);
/**
* Logs a message at the given level including the
* stack trace of the {@link Throwable} <code>t</code> passed as parameter.
*
* @param level the logging level
* @param message the message to log
* @param t the exception to log, including its stack trace
*/
public abstract void log(Level level, String message, Throwable t);
/**
* Logs an exception or error to be thrown.
*
* @param <T> the Throwable type
* @param t The Throwable
* @return the Throwable
*/
public <T extends Throwable> T throwing(T t);
/**
* Logs a message with parameters at the {@link Level#TRACE TRACE} level.
* @param message the message to log
* @param params parameters to the message
*/
public abstract void trace(String message, Object... params);
/**
* Logs a message at the {@link Level#TRACE TRACE} level including the
* stack trace of the {@link Throwable} <code>t</code> passed as parameter.
*
* @param message the message object to log
* @param t the exception to log, including its stack trace
*/
public abstract void trace(String message, Throwable t);
/**
* Logs a message with parameters at the {@link Level#WARN WARN} level.
*
* @param message the message to log
* @param params parameters to the message
*/
public abstract void warn(String message, Object... params);
/**
* Logs a message at the {@link Level#WARN WARN} level including the
* stack trace of the {@link Throwable} <code>t</code> passed as parameter.
*
* @param message the message object to log
* @param t the exception to log, including its stack trace
*/
public abstract void warn(String message, Throwable t);
}
@@ -0,0 +1,36 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.asm.logging;
public enum Level {
FATAL,
ERROR,
WARN,
INFO,
DEBUG,
TRACE;
}
@@ -0,0 +1,152 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.asm.logging;
/**
* Abstract base adapter which contains convenience methods for formatting
* log4j2-style messages and also routes all level-specific overloads to calls
* to <tt>log</tt>, which can simplify some implementations.
*/
public abstract class LoggerAdapterAbstract implements ILogger {
/**
* Logger id
*/
private final String id;
/**
* @param id Logger id
*/
protected LoggerAdapterAbstract(String id) {
this.id = id;
}
/**
* Get the id of this logger
*/
@Override
public String getId() {
return this.id;
}
/**
* This is a very naive implementation of log4j2's
* ParameterizedMessage::format method which is less efficient and less
* defensive because it doesn't need to handle all the cases that the log4j2
* formatter does. All we're really doing here is substituting in the values
* for <tt>{}</tt> placeholders because I know that in mixin there aren't
* any cases where we need to handle anything else, such as escaped <tt>{
* </tt> characters or whatever.
*
* @param message Message patterm
* @param params Message parameters
* @return Message with {} placeholders filled in
*/
protected static String getFormattedMessage(String message, Object... params) {
if (params.length == 0) {
return message;
}
StringBuilder sb = new StringBuilder();
int pos = 0;
for (int param = 0; pos < message.length() && param < params.length; param++) {
int delimPos = message.indexOf("{}", pos);
if (delimPos < 0) {
return sb.append(message.substring(pos)).toString();
}
sb.append(message.substring(pos, delimPos)).append(params[param]);
pos = delimPos + 2;
}
if (pos < message.length()) {
sb.append(message.substring(pos));
}
return sb.toString();
}
@Override
public void catching(Throwable t) {
this.catching(Level.WARN, t);
}
@Override
public void debug(String message, Object... params) {
this.log(Level.DEBUG, message, params);
}
@Override
public void debug(String message, Throwable t) {
this.log(Level.DEBUG, message, t);
}
@Override
public void error(String message, Object... params) {
this.log(Level.ERROR, message, params);
}
@Override
public void error(String message, Throwable t) {
this.log(Level.ERROR, message, t);
}
@Override
public void fatal(String message, Object... params) {
this.log(Level.FATAL, message, params);
}
@Override
public void fatal(String message, Throwable t) {
this.log(Level.FATAL, message, t);
}
@Override
public void info(String message, Object... params) {
this.log(Level.INFO, message, params);
}
@Override
public void info(String message, Throwable t) {
this.log(Level.INFO, message, t);
}
@Override
public void trace(String message, Object... params) {
this.log(Level.TRACE, message, params);
}
@Override
public void trace(String message, Throwable t) {
this.log(Level.TRACE, message, t);
}
@Override
public void warn(String message, Object... params) {
this.log(Level.WARN, message, params);
}
@Override
public void warn(String message, Throwable t) {
this.log(Level.WARN, message, t);
}
}
@@ -0,0 +1,112 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.asm.logging;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.google.common.base.Strings;
/**
* A very basic logger adapter which does not log anything to file and simply
* emits formatted log messages to the console printstreams
*/
public class LoggerAdapterConsole extends LoggerAdapterAbstract {
/**
* Date format for console messages
*/
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss");
/**
* Printstream for DEBUG-level messages, null by default
*/
private PrintStream debug;
/**
* @param name Logger name
*/
public LoggerAdapterConsole(String name) {
super(Strings.nullToEmpty(name));
}
@Override
public String getType() {
return "Default Console Logger";
}
/**
* Set output stream for DEBUG-level messages
*
* @param debug New PrintStream for debug messages
* @return fluent
*/
public LoggerAdapterConsole setDebugStream(PrintStream debug) {
this.debug = debug;
return this;
}
@Override
public void catching(Level level, Throwable t) {
this.log(Level.WARN, "Catching", t);
}
@Override
public void log(Level level, String message, Object... params) {
PrintStream out = this.getOutputStream(level);
if (out != null) {
String formatted = LoggerAdapterAbstract.getFormattedMessage(message, params);
out.println(String.format("[%s] [%s/%s] %s", LoggerAdapterConsole.DATE_FORMAT.format(new Date()), this.getId(), level, formatted));
}
}
@Override
public void log(Level level, String message, Throwable t) {
PrintStream out = this.getOutputStream(level);
if (out != null) {
out.println(String.format("[%s] [%s/%s] %s", LoggerAdapterConsole.DATE_FORMAT.format(new Date()), this.getId(), level, message));
t.printStackTrace();
}
}
@Override
public <T extends Throwable> T throwing(T t) {
this.log(Level.WARN, "Throwing", t);
return t;
}
private PrintStream getOutputStream(Level level) {
if (level == Level.FATAL || level == Level.ERROR || level == Level.WARN) {
return System.err;
} else if (level == Level.INFO) {
return System.out;
} else if (level == Level.DEBUG) {
return this.debug;
}
return null;
}
}
@@ -0,0 +1,60 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.asm.logging;
/**
* Default logger adapter which sinks log messages but doesn't emit them
* anywhere, used only in cases where no logging framework is available and no
* logging is desired.
*/
public class LoggerAdapterDefault extends LoggerAdapterAbstract {
public LoggerAdapterDefault(String name) {
super(name);
}
@Override
public String getType() {
return "Default Logger (No Logging)";
}
@Override
public void catching(Level level, Throwable t) {
}
@Override
public void log(Level level, String message, Object... params) {
}
@Override
public void log(Level level, String message, Throwable t) {
}
@Override
public <T extends Throwable> T throwing(T t) {
return null;
}
}
@@ -0,0 +1,154 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.asm.logging;
import java.util.logging.LogManager;
import java.util.logging.Logger;
/**
* Logger adapter which uses the
*/
public class LoggerAdapterJava extends LoggerAdapterAbstract {
private static final java.util.logging.Level[] LEVELS = {
/* FATAL = */ java.util.logging.Level.SEVERE,
/* ERROR = */ java.util.logging.Level.SEVERE,
/* WARN = */ java.util.logging.Level.WARNING,
/* INFO = */ java.util.logging.Level.INFO,
/* DEBUG = */ java.util.logging.Level.FINE,
/* TRACE = */ java.util.logging.Level.FINER
};
private final Logger logger;
public LoggerAdapterJava(String name) {
super(name);
this.logger = LoggerAdapterJava.getLogger(name);
}
@Override
public String getType() {
return "Default Console Logger";
}
@Override
public void catching(Level level, Throwable t) {
this.warn("Catching", t);
}
@Override
public void debug(String message, Object... params) {
this.logger.fine(LoggerAdapterAbstract.getFormattedMessage(message, params));
}
@Override
public void debug(String message, Throwable t) {
this.logger.fine(message);
this.logger.fine(t.toString());
}
@Override
public void error(String message, Object... params) {
this.logger.severe(LoggerAdapterAbstract.getFormattedMessage(message, params));
}
@Override
public void error(String message, Throwable t) {
this.logger.severe(message);
this.logger.severe(t.toString());
}
@Override
public void fatal(String message, Object... params) {
this.logger.severe(LoggerAdapterAbstract.getFormattedMessage(message, params));
}
@Override
public void fatal(String message, Throwable t) {
this.logger.severe(message);
this.logger.severe(t.toString());
}
@Override
public void info(String message, Object... params) {
this.logger.info(LoggerAdapterAbstract.getFormattedMessage(message, params));
}
@Override
public void info(String message, Throwable t) {
this.logger.info(message);
this.logger.info(t.toString());
}
@Override
public void log(Level level, String message, Object... params) {
this.logger.log(LoggerAdapterJava.LEVELS[level.ordinal()], LoggerAdapterAbstract.getFormattedMessage(message, params));
}
@Override
public void log(Level level, String message, Throwable t) {
java.util.logging.Level logLevel = LoggerAdapterJava.LEVELS[level.ordinal()];
this.logger.log(logLevel, message);
this.logger.log(logLevel, t.toString());
}
@Override
public <T extends Throwable> T throwing(T t) {
this.warn("Throwing", t);
return t;
}
@Override
public void trace(String message, Object... params) {
this.logger.finer(LoggerAdapterAbstract.getFormattedMessage(message, params));
}
@Override
public void trace(String message, Throwable t) {
this.logger.finer(message);
this.logger.finer(t.toString());
}
@Override
public void warn(String message, Object... params) {
this.logger.warning(LoggerAdapterAbstract.getFormattedMessage(message, params));
}
@Override
public void warn(String message, Throwable t) {
this.logger.warning(message);
this.logger.warning(t.toString());
}
private static Logger getLogger(String name) {
LogManager logManager = LogManager.getLogManager();
Logger logger = logManager.getLogger(name);
if (logger != null) {
return logger;
}
return LogManager.getLogManager().getLogger(Logger.GLOBAL_LOGGER_NAME);
}
}
@@ -0,0 +1,30 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* Centrallised logging so that all logging can be delegated to a logging
* adapter supplied by the mixin service
*/
package org.spongepowered.asm.logging;
@@ -33,9 +33,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.Level;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.launch.GlobalProperties;
import org.spongepowered.asm.launch.GlobalProperties.Keys;
import org.spongepowered.asm.launch.MixinBootstrap;
@@ -1034,7 +1033,7 @@ public final class MixinEnvironment implements ITokenProvider {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Performance profiler
@@ -1139,7 +1138,8 @@ public final class MixinEnvironment implements ITokenProvider {
printer.kv("Detected ASM Supports Java", ASM.getClassVersionString()).hr();
printer.kv("Service Name", serviceName);
printer.kv("Mixin Service Class", this.service.getClass().getName());
printer.kv("Global Property Service Class", MixinService.getGlobalPropertyService().getClass().getName()).hr();
printer.kv("Global Property Service Class", MixinService.getGlobalPropertyService().getClass().getName());
printer.kv("Logger Adapter Type", MixinService.getService().getLogger("mixin").getType()).hr();
for (Option option : Option.values()) {
StringBuilder indent = new StringBuilder();
for (int i = 0; i < option.depth; i++) {
@@ -29,13 +29,13 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.launch.GlobalProperties;
import org.spongepowered.asm.launch.GlobalProperties.Keys;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.mixin.transformer.ClassInfo;
import org.spongepowered.asm.mixin.transformer.Config;
import org.spongepowered.asm.service.MixinService;
/**
* Entry point for registering global mixin resources. Compatibility with
@@ -47,7 +47,7 @@ public final class Mixins {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* GlobalProperties key storing mixin configs which are pending
@@ -24,7 +24,7 @@
*/
package org.spongepowered.asm.mixin.extensibility;
import org.apache.logging.log4j.Level;
import org.spongepowered.asm.logging.Level;
/**
* Interface for objects which want to perform custom behaviour when fatal mixin
@@ -26,11 +26,11 @@ package org.spongepowered.asm.mixin.gen;
import java.util.ArrayList;
import org.apache.logging.log4j.LogManager;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.gen.throwables.InvalidAccessorException;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.asm.ASM;
/**
@@ -58,7 +58,7 @@ public abstract class AccessorGenerator {
if (!this.targetIsStatic) {
throw new InvalidAccessorException(this.info, String.format("%s is invalid. Accessor method is static but the target is not.", this.info));
} else {
LogManager.getLogger("mixin").info("{} should be static as its target is", this.info);
MixinService.getService().getLogger("mixin").info("{} should be static as its target is", this.info);
}
}
}
@@ -24,7 +24,6 @@
*/
package org.spongepowered.asm.mixin.gen;
import org.apache.logging.log4j.LogManager;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.InsnNode;
@@ -35,6 +34,7 @@ import org.spongepowered.asm.mixin.gen.throwables.InvalidAccessorException;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Bytecode;
/**
@@ -68,7 +68,7 @@ public class AccessorGeneratorFieldSetter extends AccessorGeneratorField {
}
if (this.info.getMixin().getOption(Option.DEBUG_VERBOSE)) {
LogManager.getLogger("mixin").warn("{} for final field {}::{} is not @Mutable", this.info,
MixinService.getService().getLogger("mixin").warn("{} for final field {}::{} is not @Mutable", this.info,
((MixinTargetContext)this.info.getMixin()).getTarget(), this.targetField.name);
}
}
@@ -33,7 +33,6 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.logging.log4j.LogManager;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
@@ -48,6 +47,7 @@ import org.spongepowered.asm.mixin.injection.selectors.TargetSelector.Result;
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
import org.spongepowered.asm.mixin.struct.SpecialMethodInfo;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.Bytecode;
@@ -400,7 +400,7 @@ public class AccessorInfo extends SpecialMethodInfo {
public static String inflectTarget(AccessorName name, AccessorType type, String description, ISelectorContext context, boolean verbose) {
if (name != null) {
if (!type.isExpectedPrefix(name.prefix) && verbose) {
LogManager.getLogger("mixin").warn("Unexpected prefix for {}, found [{}] expecting {}", description, name.prefix,
MixinService.getService().getLogger("mixin").warn("Unexpected prefix for {}, found [{}] expecting {}", description, name.prefix,
type.getExpectedPrefixes());
}
return TargetSelector.parseName(name.name, context);
@@ -41,7 +41,6 @@ import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.InsnList;
@@ -861,7 +860,7 @@ public abstract class InjectionPoint {
by, context, method.name, limitBreached, allowed, advice);
if (err == ShiftByViolationBehaviour.WARN && allowed < InjectionPoint.MAX_ALLOWED_SHIFT_BY) {
LogManager.getLogger("mixin").warn(message);
MixinService.getService().getLogger("mixin").warn(message);
return;
}
@@ -904,10 +903,10 @@ public abstract class InjectionPoint {
Class<? extends InjectionPoint> existing = InjectionPoint.types.get(code.value());
if (existing != null && !existing.equals(type)) {
LogManager.getLogger("mixin").debug("Overriding InjectionPoint {} with {} (previously {})", code.value(), type.getName(),
MixinService.getService().getLogger("mixin").debug("Overriding InjectionPoint {} with {} (previously {})", code.value(), type.getName(),
existing.getName());
} else if (Strings.isNullOrEmpty(namespace)) {
LogManager.getLogger("mixin").warn("Registration of InjectionPoint {} with {} without specifying namespace is deprecated.",
MixinService.getService().getLogger("mixin").warn("Registration of InjectionPoint {} with {} without specifying namespace is deprecated.",
code.value(), type.getName());
}
@@ -34,8 +34,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*;
@@ -54,6 +53,7 @@ import org.spongepowered.asm.mixin.refmap.IMixinContext;
import org.spongepowered.asm.mixin.transformer.ClassInfo;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal;
import org.spongepowered.asm.mixin.transformer.ClassInfo.TypeLookup;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.SignaturePrinter;
@@ -166,7 +166,7 @@ public abstract class Injector {
/**
* Log more things
*/
protected static final Logger logger = LogManager.getLogger("mixin");
protected static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Injection info
@@ -29,8 +29,7 @@ import java.util.LinkedList;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.InsnList;
@@ -43,6 +42,7 @@ import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.struct.InjectionPointAnnotationContext;
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
import org.spongepowered.asm.mixin.injection.throwables.InvalidSliceException;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
import com.google.common.base.Strings;
@@ -296,7 +296,7 @@ public final class MethodSlice {
/**
* Make with the logging already
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Owner of this slice
@@ -24,7 +24,7 @@
*/
package org.spongepowered.asm.mixin.injection.invoke;
import org.apache.logging.log4j.Level;
import org.spongepowered.asm.logging.Level;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
@@ -27,8 +27,7 @@ package org.spongepowered.asm.mixin.injection.invoke.arg;
import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
@@ -43,6 +42,7 @@ import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.transformer.SyntheticClassInfo;
import org.spongepowered.asm.mixin.transformer.ext.IClassGenerator;
import org.spongepowered.asm.service.ISyntheticClassInfo;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.Constants;
import org.spongepowered.asm.util.IConsumer;
@@ -89,7 +89,7 @@ public final class ArgsClassGenerator implements IClassGenerator {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Synthetic class info for args class
@@ -24,8 +24,7 @@
*/
package org.spongepowered.asm.mixin.injection.invoke.util;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.analysis.Analyzer;
import org.objectweb.asm.tree.analysis.AnalyzerException;
@@ -34,6 +33,7 @@ import org.objectweb.asm.tree.analysis.BasicValue;
import org.objectweb.asm.tree.analysis.Frame;
import org.objectweb.asm.tree.analysis.Interpreter;
import org.spongepowered.asm.mixin.injection.struct.Target;
import org.spongepowered.asm.service.MixinService;
/**
* Utility class for finding instructions using static analysis
@@ -149,7 +149,7 @@ public class InsnFinder {
/**
* Log more things
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Find the instruction which pops the value pushed by the specified
@@ -32,8 +32,7 @@ import java.util.ListIterator;
import java.util.Locale;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
@@ -49,6 +48,7 @@ import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
import org.spongepowered.asm.mixin.refmap.IMixinContext;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.Constants;
@@ -124,7 +124,7 @@ import com.google.common.primitives.Longs;
@AtCode("CONSTANT")
public class BeforeConstant extends InjectionPoint {
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Ordinal of the target insn
@@ -28,8 +28,7 @@ import java.util.Collection;
import java.util.ListIterator;
import java.util.Locale;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
@@ -46,6 +45,7 @@ import org.spongepowered.asm.mixin.injection.selectors.throwables.SelectorConstr
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
import org.spongepowered.asm.mixin.refmap.IMixinContext;
import org.spongepowered.asm.service.MixinService;
/**
* <p>This injection point searches for INVOKEVIRTUAL, INVOKESTATIC and
@@ -122,7 +122,7 @@ public class BeforeInvoke extends InjectionPoint {
/**
* Logger reference
*/
protected final Logger logger = LogManager.getLogger("mixin");
protected final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* True to turn on strategy debugging to the console
@@ -30,11 +30,11 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.Group;
import org.spongepowered.asm.mixin.injection.throwables.InjectionValidationException;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
/**
@@ -207,7 +207,7 @@ public class InjectorGroupInfo {
+ min + " on " + this);
}
if (this.minCallbackCount > 0 && this.minCallbackCount != min) {
LogManager.getLogger("mixin").warn("Conflicting min value '{}' on @Group({}), previously specified {}", min, this.name,
MixinService.getService().getLogger("mixin").warn("Conflicting min value '{}' on @Group({}), previously specified {}", min, this.name,
this.minCallbackCount);
}
this.minCallbackCount = Math.max(this.minCallbackCount, min);
@@ -227,7 +227,7 @@ public class InjectorGroupInfo {
+ max + " on " + this);
}
if (this.maxCallbackCount < Integer.MAX_VALUE && this.maxCallbackCount != max) {
LogManager.getLogger("mixin").warn("Conflicting max value '{}' on @Group({}), previously specified {}", max, this.name,
MixinService.getService().getLogger("mixin").warn("Conflicting max value '{}' on @Group({}), previously specified {}", max, this.name,
this.maxCallbackCount);
}
this.maxCallbackCount = Math.min(this.maxCallbackCount, max);
@@ -24,14 +24,15 @@
*/
package org.spongepowered.asm.mixin.refmap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.Type;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.extensibility.IRemapper;
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
import org.spongepowered.asm.mixin.transformer.ClassInfo;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.ObfuscationUtil;
import org.spongepowered.asm.util.Quantifier;
@@ -47,7 +48,7 @@ public final class RemappingReferenceMapper implements IClassReferenceMapper, IR
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* The "inner" refmap, this is the original refmap specified in the config
@@ -34,9 +34,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.Level;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
@@ -662,7 +661,7 @@ public final class ClassInfo {
}
}
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
private static final Profiler profiler = MixinEnvironment.getProfiler();
@@ -27,11 +27,11 @@ package org.spongepowered.asm.mixin.transformer;
import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.launch.MixinInitialisationError;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.extensibility.IMixinConfig;
import org.spongepowered.asm.service.MixinService;
import com.google.common.base.Strings;
@@ -43,7 +43,7 @@ public class Config {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* All loaded configs, stored by name so that parents can be assigned
@@ -29,8 +29,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.commons.Remapper;
@@ -255,7 +254,7 @@ final class InnerClassGenerator implements IClassGenerator {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Synthetic class registry
@@ -29,14 +29,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
import org.spongepowered.asm.mixin.transformer.MixinInfo.MixinMethodNode;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Counter;
import com.google.common.base.Strings;
@@ -49,7 +49,7 @@ class MethodMapper {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
private static final List<String> classes = new ArrayList<String>();
@@ -28,8 +28,7 @@ import java.lang.annotation.Annotation;
import java.util.*;
import java.util.Map.Entry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
@@ -222,7 +221,7 @@ class MixinApplicatorStandard {
/**
* Log more things
*/
protected final Logger logger = LogManager.getLogger("mixin");
protected final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Target class context
@@ -815,7 +814,7 @@ class MixinApplicatorStandard {
ctor = mixinMethod;
} else {
// Not an error condition, just weird
this.logger.warn(String.format("Mixin %s has multiple constructors, %s was selected\n", mixin, ctor.desc));
this.logger.warn("Mixin {} has multiple constructors, {} was selected\n", mixin, ctor.desc);
}
}
}
@@ -26,8 +26,7 @@ package org.spongepowered.asm.mixin.transformer;
import java.util.Locale;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.transformer.ext.Extensions;
@@ -45,7 +44,7 @@ public class MixinClassGenerator {
/**
* Log things for stuff
*/
static final Logger logger = LogManager.getLogger("mixin");
static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Transformer extensions
@@ -31,9 +31,8 @@ import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.Level;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.launch.MixinInitialisationError;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
@@ -161,7 +160,7 @@ final class MixinConfig implements Comparable<MixinConfig>, IMixinConfig {
/**
* Log even more things
*/
private final Logger logger = LogManager.getLogger("mixin");
private final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Map of mixin target classes to mixin infos
@@ -33,9 +33,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.Level;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Handle;
import org.objectweb.asm.MethodVisitor;
@@ -68,6 +67,7 @@ import org.spongepowered.asm.mixin.transformer.throwables.MixinReloadException;
import org.spongepowered.asm.mixin.transformer.throwables.MixinTargetAlreadyLoadedException;
import org.spongepowered.asm.service.IClassTracker;
import org.spongepowered.asm.service.IMixinService;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.LanguageFeatures;
@@ -736,7 +736,7 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
/**
* Logger
*/
private final transient Logger logger = LogManager.getLogger("mixin");
private final transient ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Profiler
@@ -27,8 +27,7 @@ package org.spongepowered.asm.mixin.transformer;
import java.lang.annotation.Annotation;
import java.util.Iterator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
@@ -57,6 +56,7 @@ import org.spongepowered.asm.mixin.transformer.ext.Extensions;
import org.spongepowered.asm.mixin.transformer.meta.MixinRenamed;
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
import org.spongepowered.asm.mixin.transformer.throwables.MixinPreProcessorException;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.Bytecode.Visibility;
@@ -129,7 +129,7 @@ class MixinPreProcessorStandard {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* The mixin
@@ -176,7 +176,7 @@ class MixinPreProcessorStandard {
try {
IActivity activity = this.activities.begin("Prepare inner classes");
this.prepareInnerClasses(extensions);
activity.next("Prepare method");
for (MixinMethodNode mixinMethod : this.classNode.mixinMethods) {
Method method = this.mixin.getClassInfo().findMethod(mixinMethod);
@@ -27,9 +27,8 @@ package org.spongepowered.asm.mixin.transformer;
import java.text.DecimalFormat;
import java.util.*;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.Level;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.Mixin;
@@ -143,7 +142,7 @@ class MixinProcessor {
/**
* Log all the things
*/
static final Logger logger = LogManager.getLogger("mixin");
static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Service
@@ -247,7 +246,7 @@ class MixinProcessor {
unhandled.addAll(config.getUnhandledTargets());
}
Logger auditLogger = LogManager.getLogger("mixin/audit");
ILogger auditLogger = MixinService.getService().getLogger("mixin.audit");
for (String target : unhandled) {
try {
@@ -36,9 +36,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.Level;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.ConstantDynamic;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Opcodes;
@@ -72,6 +71,7 @@ import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
import org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError;
import org.spongepowered.asm.obfuscation.RemapperChain;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.Bytecode.Visibility;
@@ -96,7 +96,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Activity tracker
@@ -28,13 +28,13 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.mixin.throwables.CompanionPluginError;
import org.spongepowered.asm.service.IMixinService;
import org.spongepowered.asm.service.MixinService;
import com.google.common.base.Strings;
@@ -66,7 +66,7 @@ class PluginHandle {
}
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Parent config which owns this plugin handle
@@ -33,8 +33,7 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
@@ -48,6 +47,7 @@ import org.spongepowered.asm.mixin.transformer.ext.Extensions;
import org.spongepowered.asm.mixin.transformer.ext.ITargetClassContext;
import org.spongepowered.asm.mixin.transformer.ext.extensions.ExtensionCheckClass.ValidationFailedException;
import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Annotations;
import org.spongepowered.asm.util.Bytecode;
import org.spongepowered.asm.util.ClassSignature;
@@ -62,7 +62,7 @@ final class TargetClassContext extends ClassContext implements ITargetClassConte
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Mixin environment
@@ -33,8 +33,7 @@ import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
@@ -44,6 +43,7 @@ import org.spongepowered.asm.mixin.transformer.ClassInfo.SearchType;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal;
import org.spongepowered.asm.mixin.transformer.ext.IExtension;
import org.spongepowered.asm.mixin.transformer.ext.ITargetClassContext;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.Constants;
import org.spongepowered.asm.util.PrettyPrinter;
import org.spongepowered.asm.util.SignaturePrinter;
@@ -64,7 +64,7 @@ public class ExtensionCheckInterfaces implements IExtension {
private static final String IMPL_REPORT_CSV_FILENAME = ExtensionCheckInterfaces.IMPL_REPORT_FILENAME + ".csv";
private static final String IMPL_REPORT_TXT_FILENAME = ExtensionCheckInterfaces.IMPL_REPORT_FILENAME + ".txt";
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* CSV Report file
@@ -29,8 +29,7 @@ import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.regex.Pattern;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
@@ -38,6 +37,7 @@ import org.spongepowered.asm.mixin.MixinEnvironment.Option;
import org.spongepowered.asm.mixin.transformer.ext.IDecompiler;
import org.spongepowered.asm.mixin.transformer.ext.IExtension;
import org.spongepowered.asm.mixin.transformer.ext.ITargetClassContext;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.transformers.MixinClassWriter;
import org.spongepowered.asm.util.Constants;
import org.spongepowered.asm.util.perf.Profiler.Section;
@@ -59,7 +59,7 @@ public class ExtensionClassExporter implements IExtension {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
/**
* Directory to export classes to when debug.export is enabled
@@ -28,6 +28,7 @@ import java.io.InputStream;
import java.util.Collection;
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.util.ReEntranceLock;
@@ -181,5 +182,24 @@ public interface IMixinService {
* @return minimum supported {@link CompatibilityLevel} or null
*/
public abstract CompatibilityLevel getMaxCompatibilityLevel();
/**
* Retrieve a logger adapter with the specified name (id). In general this
* method will be called many times for a given name so it is anticipated
* that the returned logger instances are cached by the service.
*
* <p>There is no contractual requirement however that adapters are cached
* and that the same adapter is returned for every call to this method with
* the same name.</p>
*
* <p>This methood <em>must not return <tt>null</tt></em>.</p>
*
* <p>Implementations should be thread-safe since loggers may be requested
* by threads other than the main application thread.</p>
*
* @param name Logger name
* @return Logger adapter for the underlying logging subsystem
*/
public abstract ILogger getLogger(final String name);
}
@@ -32,10 +32,11 @@ import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.logging.LoggerAdapterConsole;
import com.google.common.base.Joiner;
import com.google.common.collect.ObjectArrays;
/**
* Provides access to the service layer which connects the mixin transformer to
@@ -46,10 +47,71 @@ import com.google.common.base.Joiner;
public final class MixinService {
/**
* Log all the things
* Since we want to log things during startup but need the service itself to
* provide a logging implementation adapter, we need a place to store log
* messages prior to the service startup which can later be flushed into the
* logger itself if startup succeeds, or into the console if startup fails.
*/
private static final Logger logger = LogManager.getLogger("mixin");
static class LogBuffer {
public static class LogEntry {
public String message;
public Object[] params;
public Throwable t;
public LogEntry(String message, Object[] params, Throwable t) {
this.message = message;
this.params = params;
this.t = t;
}
}
private final List<LogEntry> buffer = new ArrayList<LogEntry>();
private ILogger logger;
synchronized void debug(String message, Object... params) {
if (this.logger != null) {
this.logger.debug(message, params);
return;
}
this.buffer.add(new LogEntry(message, params, null));
}
synchronized void debug(String message, Throwable t) {
if (this.logger != null) {
this.logger.debug(message, t);
return;
}
this.buffer.add(new LogEntry(message, new Object[0], t));
}
/**
* Flush the contents of the buffer into the specified logger
*/
synchronized void flush(ILogger logger) {
for (LogEntry buffered : this.buffer) {
if (buffered.t != null) {
logger.debug(buffered.message, ObjectArrays.concat(buffered.params, buffered.t));
} else {
logger.debug(buffered.message, buffered.params);
}
}
this.buffer.clear();
this.logger = logger;
}
}
/**
* Log buffer for messages generated during service startup but before the
* actual logger can be retrieved from the service, flushed once the service
* is started
*/
private static LogBuffer logBuffer = new LogBuffer();
/**
* Singleton
*/
@@ -91,9 +153,10 @@ public final class MixinService {
this.bootedServices.add(bootService.getServiceClassName());
} catch (ServiceInitialisationException ex) {
// Expected if service cannot start
MixinService.logger.debug("Mixin bootstrap service {} is not available: {}", ex.getStackTrace()[0].getClassName(), ex.getMessage());
MixinService.logBuffer.debug("Mixin bootstrap service {} is not available: {}", ex.getStackTrace()[0].getClassName(),
ex.getMessage());
} catch (Throwable th) {
MixinService.logger.debug("Catching {}:{} initialising service", th.getClass().getName(), th.getMessage(), th);
MixinService.logBuffer.debug("Catching {}:{} initialising service", th.getClass().getName(), th.getMessage(), th);
}
}
}
@@ -122,7 +185,16 @@ public final class MixinService {
private synchronized IMixinService getServiceInstance() {
if (this.service == null) {
this.service = this.initService();
try {
this.service = this.initService();
ILogger serviceLogger = this.service.getLogger("mixin");
MixinService.logBuffer.flush(serviceLogger);
} catch (Error err) {
ILogger defaultLogger = MixinService.<ILogger>getDefaultLogger();
MixinService.logBuffer.flush(defaultLogger);
defaultLogger.error(err.getMessage(), err);
throw err;
}
}
return this.service;
}
@@ -136,19 +208,20 @@ public final class MixinService {
try {
IMixinService service = iter.next();
if (this.bootedServices.contains(service.getClass().getName())) {
MixinService.logger.debug("MixinService [{}] was successfully booted in {}", service.getName(), this.getClass().getClassLoader());
MixinService.logBuffer.debug("MixinService [{}] was successfully booted in {}", service.getName(),
this.getClass().getClassLoader());
}
if (service.isValid()) {
return service;
}
MixinService.logger.debug("MixinService [{}] is not valid", service.getName());
MixinService.logBuffer.debug("MixinService [{}] is not valid", service.getName());
badServices.add(String.format("INVALID[%s]", service.getName()));
} catch (ServiceConfigurationError sce) {
// sce.printStackTrace();
brokenServiceCount++;
} catch (Throwable th) {
String faultingClassName = th.getStackTrace()[0].getClassName();
MixinService.logger.debug("MixinService [{}] failed initialisation: {}", faultingClassName, th.getMessage());
MixinService.logBuffer.debug("MixinService [{}] failed initialisation: {}", faultingClassName, th.getMessage());
int pos = faultingClassName.lastIndexOf('.');
badServices.add(String.format("ERROR[%s]", pos < 0 ? faultingClassName : faultingClassName.substring(pos + 1)));
// th.printStackTrace();
@@ -195,4 +268,14 @@ public final class MixinService {
}
throw new ServiceNotAvailableError("No mixin global property service is available");
}
/**
* Returns Object so that ILogger is not classloaded until after it doesn't
* matter any more
*/
@SuppressWarnings("unchecked")
private static <T> T getDefaultLogger() {
return (T)new LoggerAdapterConsole("mixin").setDebugStream(System.err);
}
}
@@ -30,11 +30,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.launch.platform.IMixinPlatformAgent;
import org.spongepowered.asm.launch.platform.IMixinPlatformServiceAgent;
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.logging.LoggerAdapterDefault;
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.util.Constants;
@@ -55,9 +55,15 @@ public abstract class MixinServiceAbstract implements IMixinService {
protected static final String SERVICE_PACKAGE = "org.spongepowered.asm.service.";
/**
* Logger
* Logger adapter, replacement for log4j2 logger as services should use
* their own loggers now in order to avoid contamination
*/
protected static final Logger logger = LogManager.getLogger("mixin");
private static ILogger logger;
/**
* Cached logger adapters
*/
private static final Map<String, ILogger> loggers = new HashMap<String, ILogger>();
/**
* Transformer re-entrance lock, shared between the mixin transformer and
@@ -79,6 +85,12 @@ public abstract class MixinServiceAbstract implements IMixinService {
* Detected side name
*/
private String sideName;
protected MixinServiceAbstract() {
if (MixinServiceAbstract.logger == null) {
MixinServiceAbstract.logger = this.getLogger("mixin");
}
}
/* (non-Javadoc)
* @see org.spongepowered.asm.service.IMixinService#prepare()
@@ -241,6 +253,19 @@ public abstract class MixinServiceAbstract implements IMixinService {
}
return this.serviceAgents;
}
@Override
public synchronized ILogger getLogger(final String name) {
ILogger logger = MixinServiceAbstract.loggers.get(name);
if (logger == null) {
MixinServiceAbstract.loggers.put(name, logger = this.createLogger(name));
}
return logger;
}
protected ILogger createLogger(final String name) {
return new LoggerAdapterDefault(name);
}
// AMS - TEMP WIRING TO AVOID THE COMPLEXITY OF MERGING MULTIPHASE WITH 0.8
@@ -32,8 +32,6 @@ import java.util.List;
import java.util.ListIterator;
import java.util.regex.Pattern;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
@@ -43,6 +41,7 @@ import org.spongepowered.asm.mixin.Debug;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.util.asm.IAnnotationHandle;
import com.google.common.base.Function;
@@ -147,8 +146,6 @@ public final class Annotations {
private static Pattern mergeableAnnotationPattern = Annotations.getMergeableAnnotationPattern();
private static final Logger logger = LogManager.getLogger("mixin");
private Annotations() {
// Utility class
}
@@ -758,7 +755,7 @@ public final class Annotations {
to.add(annotation);
}
} catch (Exception ex) {
Annotations.logger.warn("Exception encountered whilst merging annotations for {} {}", type, name);
MixinService.getService().getLogger("mixin").warn("Exception encountered whilst merging annotations for {} {}", type, name);
}
return to;
@@ -32,9 +32,9 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.logging.Level;
import org.spongepowered.asm.service.MixinService;
import com.google.common.base.Strings;
@@ -948,7 +948,7 @@ public class PrettyPrinter {
* @return fluent interface
*/
public PrettyPrinter trace(String logger) {
return this.trace(System.err, LogManager.getLogger(logger));
return this.trace(System.err, MixinService.getService().getLogger(logger));
}
/**
@@ -960,7 +960,7 @@ public class PrettyPrinter {
* @return fluent interface
*/
public PrettyPrinter trace(String logger, Level level) {
return this.trace(System.err, LogManager.getLogger(logger), level);
return this.trace(System.err, MixinService.getService().getLogger(logger), level);
}
/**
@@ -970,7 +970,7 @@ public class PrettyPrinter {
* @param logger Logger to write to
* @return fluent interface
*/
public PrettyPrinter trace(Logger logger) {
public PrettyPrinter trace(ILogger logger) {
return this.trace(System.err, logger);
}
@@ -982,7 +982,7 @@ public class PrettyPrinter {
* @param level Log level to write messages
* @return fluent interface
*/
public PrettyPrinter trace(Logger logger, Level level) {
public PrettyPrinter trace(ILogger logger, Level level) {
return this.trace(System.err, logger, level);
}
@@ -1018,7 +1018,7 @@ public class PrettyPrinter {
* @return fluent interface
*/
public PrettyPrinter trace(PrintStream stream, String logger) {
return this.trace(stream, LogManager.getLogger(logger));
return this.trace(stream, MixinService.getService().getLogger(logger));
}
/**
@@ -1031,7 +1031,7 @@ public class PrettyPrinter {
* @return fluent interface
*/
public PrettyPrinter trace(PrintStream stream, String logger, Level level) {
return this.trace(stream, LogManager.getLogger(logger), level);
return this.trace(stream, MixinService.getService().getLogger(logger), level);
}
/**
@@ -1042,7 +1042,7 @@ public class PrettyPrinter {
* @param logger Logger to write to
* @return fluent interface
*/
public PrettyPrinter trace(PrintStream stream, Logger logger) {
public PrettyPrinter trace(PrintStream stream, ILogger logger) {
return this.trace(stream, logger, Level.DEBUG);
}
@@ -1055,7 +1055,7 @@ public class PrettyPrinter {
* @param level Log level to write messages
* @return fluent interface
*/
public PrettyPrinter trace(PrintStream stream, Logger logger, Level level) {
public PrettyPrinter trace(PrintStream stream, ILogger logger, Level level) {
this.log(logger, level);
this.print(stream);
return this;
@@ -1106,7 +1106,7 @@ public class PrettyPrinter {
* @param logger logger to log to
* @return fluent interface
*/
public PrettyPrinter log(Logger logger) {
public PrettyPrinter log(ILogger logger) {
return this.log(logger, Level.INFO);
}
@@ -1117,7 +1117,7 @@ public class PrettyPrinter {
* @return fluent interface
*/
public PrettyPrinter log(Level level) {
return this.log(LogManager.getLogger(PrettyPrinter.getDefaultLoggerName()), level);
return this.log(MixinService.getService().getLogger(PrettyPrinter.getDefaultLoggerName()), level);
}
/**
@@ -1127,7 +1127,7 @@ public class PrettyPrinter {
* @param level log level
* @return fluent interface
*/
public PrettyPrinter log(Logger logger, Level level) {
public PrettyPrinter log(ILogger logger, Level level) {
this.updateWidth();
this.logSpecial(logger, level, this.horizontalRule);
for (Object line : this.lines) {
@@ -1141,13 +1141,13 @@ public class PrettyPrinter {
return this;
}
private void logSpecial(Logger logger, Level level, ISpecialEntry line) {
private void logSpecial(ILogger logger, Level level, ISpecialEntry line) {
logger.log(level, "/*{}*/", line.toString());
}
private void logString(Logger logger, Level level, String line) {
private void logString(ILogger logger, Level level, String line) {
if (line != null) {
logger.log(level, String.format("/* %-" + this.width + "s */", line));
logger.log(level, "/* {} */", String.format("%-" + this.width, line));
}
}
@@ -30,9 +30,9 @@ import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic.Kind;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.Level;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.logging.ILogger;
/**
* Logging router for objects which may need to log messages during standard
@@ -49,26 +49,26 @@ public final class MessageRouter {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger("mixin");
private static final ILogger logger = MixinService.getService().getLogger("mixin");
@Override
public void printMessage(Kind kind, CharSequence msg) {
LoggingMessager.logger.log(LoggingMessager.messageKindToLoggingLevel(kind), msg);
LoggingMessager.logger.log(LoggingMessager.messageKindToLoggingLevel(kind), msg.toString());
}
@Override
public void printMessage(Kind kind, CharSequence msg, Element e) {
LoggingMessager.logger.log(LoggingMessager.messageKindToLoggingLevel(kind), msg);
LoggingMessager.logger.log(LoggingMessager.messageKindToLoggingLevel(kind), msg.toString());
}
@Override
public void printMessage(Kind kind, CharSequence msg, Element e, AnnotationMirror a) {
LoggingMessager.logger.log(LoggingMessager.messageKindToLoggingLevel(kind), msg);
LoggingMessager.logger.log(LoggingMessager.messageKindToLoggingLevel(kind), msg.toString());
}
@Override
public void printMessage(Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) {
LoggingMessager.logger.log(LoggingMessager.messageKindToLoggingLevel(kind), msg);
LoggingMessager.logger.log(LoggingMessager.messageKindToLoggingLevel(kind), msg.toString());
}
private static Level messageKindToLoggingLevel(Kind kind) {
@@ -28,8 +28,7 @@ import java.nio.file.Path;
import java.util.List;
import java.util.Map.Entry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.service.MixinService;
/**
* ModLauncher root container
@@ -65,11 +64,6 @@ public class ContainerHandleModLauncher extends ContainerHandleVirtual {
}
/**
* Logger
*/
protected static final Logger logger = LogManager.getLogger("mixin");
public ContainerHandleModLauncher(String name) {
super(name);
}
@@ -103,7 +97,7 @@ public class ContainerHandleModLauncher extends ContainerHandleVirtual {
if (resource instanceof Entry) {
this.addResource((Entry<String, Path>)resource);
} else {
ContainerHandleModLauncher.logger.error("Unrecognised resource type {} passed to {}", resource.getClass(), this);
MixinService.getService().getLogger("mixin").error("Unrecognised resource type {} passed to {}", resource.getClass(), this);
}
}
@@ -0,0 +1,140 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.asm.service.modlauncher;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.logging.Level;
import org.spongepowered.asm.logging.LoggerAdapterAbstract;
public class LoggerAdapterLog4j2 extends LoggerAdapterAbstract {
private static final org.apache.logging.log4j.Level[] LEVELS = {
/* FATAL = */ org.apache.logging.log4j.Level.FATAL,
/* ERROR = */ org.apache.logging.log4j.Level.ERROR,
/* WARN = */ org.apache.logging.log4j.Level.WARN,
/* INFO = */ org.apache.logging.log4j.Level.INFO,
/* DEBUG = */ org.apache.logging.log4j.Level.DEBUG,
/* TRACE = */ org.apache.logging.log4j.Level.TRACE
};
private final Logger logger;
public LoggerAdapterLog4j2(String name) {
super(name);
this.logger = LogManager.getLogger(name);
}
@Override
public String getType() {
return "Log4j2 (via ModLauncher)";
}
@Override
public void catching(Level level, Throwable t) {
this.logger.catching(LoggerAdapterLog4j2.LEVELS[level.ordinal()], t);
}
@Override
public void catching(Throwable t) {
this.logger.catching(t);
}
@Override
public void debug(String message, Object... params) {
this.logger.debug(message, params);
}
@Override
public void debug(String message, Throwable t) {
this.logger.debug(message, t);
}
@Override
public void error(String message, Object... params) {
this.logger.error(message, params);
}
@Override
public void error(String message, Throwable t) {
this.logger.error(message, t);
}
@Override
public void fatal(String message, Object... params) {
this.logger.fatal(message, params);
}
@Override
public void fatal(String message, Throwable t) {
this.logger.fatal(message, t);
}
@Override
public void info(String message, Object... params) {
this.logger.info(message, params);
}
@Override
public void info(String message, Throwable t) {
this.logger.info(message, t);
}
@Override
public void log(Level level, String message, Object... params) {
this.logger.log(LoggerAdapterLog4j2.LEVELS[level.ordinal()], message, params);
}
@Override
public void log(Level level, String message, Throwable t) {
this.logger.log(LoggerAdapterLog4j2.LEVELS[level.ordinal()], message, t);
}
@Override
public <T extends Throwable> T throwing(T t) {
return this.logger.throwing(t);
}
@Override
public void trace(String message, Object... params) {
this.logger.trace(message, params);
}
@Override
public void trace(String message, Throwable t) {
this.logger.trace(message, t);
}
@Override
public void warn(String message, Object... params) {
this.logger.warn(message, params);
}
@Override
public void warn(String message, Throwable t) {
this.logger.warn(message, t);
}
}
@@ -30,6 +30,7 @@ import java.util.Collection;
import org.spongepowered.asm.launch.IClassProcessor;
import org.spongepowered.asm.launch.platform.container.ContainerHandleModLauncher;
import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.mixin.transformer.IMixinTransformerFactory;
@@ -187,6 +188,11 @@ public class MixinServiceModLauncher extends MixinServiceAbstract {
public CompatibilityLevel getMinCompatibilityLevel() {
return this.minCompatibilityLevel;
}
@Override
protected ILogger createLogger(String name) {
return new LoggerAdapterLog4j2(name);
}
/* (non-Javadoc)
* @see org.spongepowered.asm.service.IMixinService#isValid()
+2
View File
@@ -43,6 +43,7 @@ module org.spongepowered.mixin {
requires transitive org.objectweb.asm.tree;
requires transitive org.objectweb.asm.tree.analysis;
requires transitive org.objectweb.asm.util;
requires java.logging;
//
// Automatic modules we depend on
@@ -59,6 +60,7 @@ module org.spongepowered.mixin {
exports org.spongepowered.asm.launch.platform.container;
exports org.spongepowered.asm.lib;
exports org.spongepowered.asm.lib.tree;
exports org.spongepowered.asm.logging;
exports org.spongepowered.asm.mixin;
exports org.spongepowered.asm.mixin.connect;
exports org.spongepowered.asm.mixin.extensibility;