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

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:
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);
      }
    }
  }

}
prettyPrint();

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
prettyPrint();

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
7 comments
j.m.baseLanguage.logging is a language which output requires commons-logging-1.1.jar. The language provides this jar as a runtime library.

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
0
Hello, Fabian

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.
0
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.
0
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!
0
(AFAIK) There should be a warning that your language should extend j.m.bl.logging, because of using these statements in generator templates.
0
For default configuration add the following line into TestUnit.generate method (before any calls to log):

BasicConfigurator.configure();

and import is

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

Please sign in to leave a comment.