Running generated code: Logging does not work (log4j error) Follow
Hello,
I'm very new to MPS, so it's my first project.
I want to generate some java code from my language and then run it directly. It was very hard to find out how to start a main class from MPS, this should really be explained in one of the tutorials.
My root concept now implements the IMainClass interface and I'm able to create a run configuration. But because I'm using the 'info ""' and 'error ""' statements in my generated class, the logging feature are enable. My class looks like this:
To compile this I had to add the dependency to jetbrains.mps.baselanguage.logging to my solution. This was hard to find out.
Now my class is compiled and executed, but the last take ages and produces this output:
I really don't know what to do now. I'm not familiar with this logging framework.
Am I using the "normal" way to execute code? Is there any document dealing this?
I would be very thankful for any help!
Fabian
I'm very new to MPS, so it's my first project.
I want to generate some java code from my language and then run it directly. It was very hard to find out how to start a main class from MPS, this should really be explained in one of the tutorials.
My root concept now implements the IMainClass interface and I'm able to create a run configuration. But because I'm using the 'info ""' and 'error ""' statements in my generated class, the logging feature are enable. My class looks like this:
package de.tuhh.ict.sehdl.base.sandbox.sandbox; /*Generated by MPS */ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.io.IOException; public class TestUnit { protected static Log log = LogFactory.getLog(TestUnit.class); ... public void generate() { ... try { ... if (log.isInfoEnabled()) { log.info(fileName + " has been generated"); } } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Can't create file: ", e); } } } }
To compile this I had to add the dependency to jetbrains.mps.baselanguage.logging to my solution. This was hard to find out.
Now my class is compiled and executed, but the last take ages and produces this output:
log4j:WARN No appenders could be found for logger (de.tuhh.ict.sehdl.base.sandbox.sandbox.TestUnit). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Process finished with exit code 0
I really don't know what to do now. I'm not familiar with this logging framework.
Am I using the "normal" way to execute code? Is there any document dealing this?
I would be very thankful for any help!
Fabian
Please sign in to leave a comment.
See:
Go To -> Go to Module -> j.m.baseLanguage.logging
Properties -> Runtime -> Runtime Libraries
If your solution uses logging language, this dependency as added automatically (as long as you use MPS to build your project). If you created a language which outputs logging statements, your language should extend logging language.
See:
your language Properties -> Dependencies -> Extended Languages
The output of you program tells you that logging is configured right and it's working, but you should configure log4j http://logging.apache.org/log4j/1.2/faq.html#noconfig to tell it what and where log should be written.
@Evgeny, I think it could be good feature for logging language to have ability configure log4j configuration in place and provide something like default configuration.
But it's strange, that I can use the logging statements without extending the logging language but can't compile the result in the solution.
Many thanks!
BasicConfigurator.configure();
and import is
import org.apache.log4j.BasicConfigurator;