Running generated code: Logging does not work (log4j error)


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;

public class TestUnit {
  protected static Log log = LogFactory.getLog(TestUnit.class);


  public void generate() {
    try {
      if (log.isInfoEnabled()) { + " 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 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!

j.m.baseLanguage.logging is a language which output requires commons-logging-1.1.jar. The language provides this jar as a runtime library.

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.

your language Properties -> Dependencies -> Extended Languages
Hello, Fabian

The output of you program tells you that logging is configured right and it's working, but you should configure log4j 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.
I haven't extended the logging language in my language module. If I do so, I don't have to add the dependency to my solution anymore.
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.
Unfortunately I can't see any output in the message box. So I need the configuration files to see any output? Then I think, too, that there should be some default ones. Are there any sample files in MPS? Where must I place them, so log4j will use them?
Many thanks!
(AFAIK) There should be a warning that your language should extend, because of using these statements in generator templates.
For default configuration add the following line into TestUnit.generate method (before any calls to log):


and import is

import org.apache.log4j.BasicConfigurator;
This works great! Thanks a lot!

Please sign in to leave a comment.