X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fjava%2FLoggingModule.java;h=c0e3be53c9efc1b20c1080ae3502d4a5be0b35fa;hb=3ccd513530bc718ef384780d3151ddbb85600986;hp=fa5059626a12b1b881a2f6d913b74d4ef3bad3bc;hpb=f5fc85ba00f434402caa2a4c83a302a3b035adce;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java index fa5059626..c0e3be53c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java @@ -2,6 +2,7 @@ package org.simantics.scl.compiler.elaboration.java; import org.cojen.classfile.TypeDesc; import org.osgi.service.component.annotations.Component; +import org.simantics.scl.compiler.commands.CommandSession; import org.simantics.scl.compiler.common.names.Name; import org.simantics.scl.compiler.constants.JavaMethod; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; @@ -26,6 +27,8 @@ public class LoggingModule extends ConcreteModule { private static String[] LOGGING_METHODS = new String[] { "trace", "debug", "info", "warn", "error" }; + + public static final TCon Throwable = Types.con("Prelude", "Throwable"); public LoggingModule() { super("Logging"); @@ -38,24 +41,55 @@ public class LoggingModule extends ConcreteModule { // Common types Type loggingType = Types.functionE(Types.STRING, Types.PROC, Types.UNIT); + Type loggingTypeWithException = Types.functionE(new Type[] { Types.STRING, Throwable }, Types.PROC, Types.UNIT); // Add logging methods for(String methodName : LOGGING_METHODS) { - JavaMethod javaMethod = new JavaMethod(false, "org/slf4j/Logger", methodName, Types.PROC, Types.UNIT, Logger, Types.STRING); - SCLValue value = new SCLValue(Name.create(getName(), methodName)); - value.setType(loggingType); - value.setMacroRule(new MacroRule() { - @Override - public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) { - ConcreteModule module = context.getCompilationContext().module; - apply.set(new ELiteral(javaMethod), new Expression[] { - new EExternalConstant(LoggerFactory.getLogger(module.getName().replaceAll("/", ".")), Logger), - apply.parameters[0] - }); - return apply; - } - }); - addValue(value); + { + JavaMethod javaMethod = new JavaMethod(false, "org/slf4j/Logger", methodName, Types.PROC, Types.UNIT, Logger, Types.STRING); + SCLValue value = new SCLValue(Name.create(getName(), methodName)); + value.setType(loggingType); + value.setMacroRule(new MacroRule() { + @Override + public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) { + ConcreteModule module = context.getCompilationContext().module; + String identifier; + if (module != null) + identifier = module.getName().replaceAll("/", "."); + else + identifier = CommandSession.class.getName(); + apply.set(new ELiteral(javaMethod), new Expression[] { + new EExternalConstant(LoggerFactory.getLogger(identifier), Logger), + apply.parameters[0] + }); + return apply; + } + }); + addValue(value); + } + { + JavaMethod javaMethod = new JavaMethod(false, "org/slf4j/Logger", methodName, Types.PROC, Types.UNIT, Logger, Types.STRING, Throwable); + SCLValue value = new SCLValue(Name.create(getName(), methodName + "E")); + value.setType(loggingTypeWithException); + value.setMacroRule(new MacroRule() { + @Override + public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) { + ConcreteModule module = context.getCompilationContext().module; + String identifier; + if (module != null) + identifier = module.getName().replaceAll("/", "."); + else + identifier = CommandSession.class.getName(); + apply.set(new ELiteral(javaMethod), new Expression[] { + new EExternalConstant(LoggerFactory.getLogger(identifier), Logger), + apply.parameters[0], + apply.parameters[1] + }); + return apply; + } + }); + addValue(value); + } } setParentClassLoader(LoggerFactory.class.getClassLoader());